From 0a1f904707fa3c170032dd9dba8f2ef9207ff9b2 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 3 Jul 2021 21:47:55 +0200 Subject: [PATCH] openocd: remove NULL comparisons with checkpatch [2/2] Patch generated automatically through a modified checkpatch that detects the patterns if (NULL == symbol) if (NULL != symbol) and through flags "--types COMPARISON_TO_NULL --fix-inplace". The unmodified checkpatch detects this pattern as Yoda condition, but it's odd fixing it as Yoda condition and then again as NULL comparison. This triggered the modification to the script. Change-Id: I5fe984a85e9c4fc799f049211797aef891ebce18 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6352 Tested-by: jenkins --- src/flash/nand/arm_io.c | 2 +- src/flash/nand/core.c | 2 +- src/flash/nor/core.c | 2 +- src/helper/binarybuffer.c | 2 +- src/jtag/adapter.c | 6 +++--- src/jtag/commands.c | 2 +- src/jtag/drivers/vsllink.c | 2 +- src/jtag/drivers/xds110.c | 8 ++++---- src/openocd.c | 2 +- src/rtos/mqx.c | 6 +++--- src/svf/svf.c | 4 ++-- src/target/target.c | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/flash/nand/arm_io.c b/src/flash/nand/arm_io.c index 705470e77..2b0c081bd 100644 --- a/src/flash/nand/arm_io.c +++ b/src/flash/nand/arm_io.c @@ -55,7 +55,7 @@ static int arm_code_to_working_area(struct target *target, */ /* make sure we have a working area */ - if (NULL == *area) { + if (!*area) { retval = target_alloc_working_area(target, size, area); if (retval != ERROR_OK) { LOG_DEBUG("%s: no %d byte buffer", __func__, (int) size); diff --git a/src/flash/nand/core.c b/src/flash/nand/core.c index d60e0d071..c1f1bc4b8 100644 --- a/src/flash/nand/core.c +++ b/src/flash/nand/core.c @@ -180,7 +180,7 @@ static struct nand_device *get_nand_device_by_name(const char *name) unsigned found = 0; struct nand_device *nand; - for (nand = nand_devices; NULL != nand; nand = nand->next) { + for (nand = nand_devices; nand; nand = nand->next) { if (strcmp(nand->name, name) == 0) return nand; if (!flash_driver_name_matches(nand->controller->name, name)) diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index a2d7623d0..30d387ae0 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -257,7 +257,7 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name) unsigned found = 0; struct flash_bank *bank; - for (bank = flash_banks; NULL != bank; bank = bank->next) { + for (bank = flash_banks; bank; bank = bank->next) { if (strcmp(bank->name, name) == 0) return bank; if (!flash_driver_name_matches(bank->driver->name, name)) diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c index 3d35702ac..49e347b6e 100644 --- a/src/helper/binarybuffer.c +++ b/src/helper/binarybuffer.c @@ -53,7 +53,7 @@ static const char hex_digits[] = { void *buf_cpy(const void *from, void *_to, unsigned size) { - if (NULL == from || NULL == _to) + if (!from || !_to) return NULL; /* copy entire buffer */ diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index b8b8f5a8f..80d5ab048 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -91,7 +91,7 @@ COMMAND_HANDLER(handle_adapter_list_command) return ERROR_COMMAND_SYNTAX_ERROR; command_print(CMD, "The following debug adapters are available:"); - for (unsigned i = 0; NULL != adapter_drivers[i]; i++) { + for (unsigned i = 0; adapter_drivers[i]; i++) { const char *name = adapter_drivers[i]->name; command_print(CMD, "%u: %s", i + 1, name); } @@ -113,11 +113,11 @@ COMMAND_HANDLER(handle_adapter_driver_command) if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0') return ERROR_COMMAND_SYNTAX_ERROR; - for (unsigned i = 0; NULL != adapter_drivers[i]; i++) { + for (unsigned i = 0; adapter_drivers[i]; i++) { if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0) continue; - if (NULL != adapter_drivers[i]->commands) { + if (adapter_drivers[i]->commands) { retval = register_commands(CMD_CTX, NULL, adapter_drivers[i]->commands); if (retval != ERROR_OK) diff --git a/src/jtag/commands.c b/src/jtag/commands.c index aacedbd67..206c5e8f5 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -67,7 +67,7 @@ void jtag_queue_command(struct jtag_command *cmd) struct jtag_command **last_cmd = next_command_pointer; assert(last_cmd); - assert(NULL == *last_cmd); + assert(!*last_cmd); *last_cmd = cmd; /* store location where the next command pointer will be stored */ diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index b4597b788..6361ee0da 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -785,7 +785,7 @@ static int vsllink_check_usb_strings( char desc_string[256]; int retval; - if (NULL != versaloon_interface.usb_setting.serialstring) { + if (versaloon_interface.usb_setting.serialstring) { retval = libusb_get_string_descriptor_ascii(usb_device_handle, usb_desc->iSerialNumber, (unsigned char *)desc_string, sizeof(desc_string)); diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index e89cfe589..f62051422 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -472,7 +472,7 @@ static bool usb_read(unsigned char *buffer, int size, int *bytes_read, { int result; - if (NULL == xds110.dev || NULL == buffer || NULL == bytes_read) + if (!xds110.dev || !buffer || !bytes_read) return false; /* Force a non-zero timeout to prevent blocking */ @@ -491,7 +491,7 @@ static bool usb_write(unsigned char *buffer, int size, int *written) int result = LIBUSB_SUCCESS; int retries = 0; - if (NULL == xds110.dev || NULL == buffer) + if (!xds110.dev || !buffer) return false; result = libusb_bulk_transfer(xds110.dev, xds110.endpoint_out, buffer, @@ -1037,7 +1037,7 @@ static bool ocd_dap_request(uint8_t *dap_requests, uint32_t request_size, bool success; - if (NULL == dap_requests || NULL == dap_results) + if (!dap_requests || !dap_results) return false; xds110.write_payload[0] = OCD_DAP_REQUEST; @@ -1062,7 +1062,7 @@ static bool ocd_scan_request(uint8_t *scan_requests, uint32_t request_size, bool success; - if (NULL == scan_requests || NULL == scan_results) + if (!scan_requests || !scan_results) return false; xds110.write_payload[0] = OCD_SCAN_REQUEST; diff --git a/src/openocd.c b/src/openocd.c index 2eb7346c5..2c9466624 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -262,7 +262,7 @@ static struct command_context *setup_command_handler(Jim_Interp *interp) &arm_tpiu_swo_register_commands, NULL }; - for (unsigned i = 0; NULL != command_registrants[i]; i++) { + for (unsigned i = 0; command_registrants[i]; i++) { int retval = (*command_registrants[i])(cmd_ctx); if (retval != ERROR_OK) { command_done(cmd_ctx); diff --git a/src/rtos/mqx.c b/src/rtos/mqx.c index 710436b74..777d23ce3 100644 --- a/src/rtos/mqx.c +++ b/src/rtos/mqx.c @@ -393,7 +393,7 @@ static int mqx_update_threads( rtos->thread_details[i].exists = true; /* set thread name */ rtos->thread_details[i].thread_name_str = malloc(strlen((void *)task_name) + 1); - if (NULL == rtos->thread_details[i].thread_name_str) + if (!rtos->thread_details[i].thread_name_str) return ERROR_FAIL; strcpy(rtos->thread_details[i].thread_name_str, (void *)task_name); /* set thread extra info @@ -405,7 +405,7 @@ static int mqx_update_threads( */ extra_info_length += strlen((void *)state_name) + 7 + 13 + 8 + 15 + 8; rtos->thread_details[i].extra_info_str = malloc(extra_info_length + 1); - if (NULL == rtos->thread_details[i].extra_info_str) + if (!rtos->thread_details[i].extra_info_str) return ERROR_FAIL; snprintf(rtos->thread_details[i].extra_info_str, extra_info_length, "State: %s, Address: 0x%" PRIx32 ", Error Code: %" PRIu32, @@ -501,7 +501,7 @@ static int mqx_get_thread_reg_list( static int mqx_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { *symbol_list = calloc(ARRAY_SIZE(mqx_symbol_list), sizeof(struct symbol_table_elem)); - if (NULL == *symbol_list) + if (!*symbol_list) return ERROR_FAIL; /* export required symbols */ for (int i = 0; i < (int)(ARRAY_SIZE(mqx_symbol_list)); i++) diff --git a/src/svf/svf.c b/src/svf/svf.c index 553bdc7e1..c93d530d2 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -761,10 +761,10 @@ static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_ { int new_byte_len = (new_bit_len + 7) >> 3; - if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) { + if ((!*arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) { free(*arr); *arr = calloc(1, new_byte_len); - if (NULL == *arr) { + if (!*arr) { LOG_ERROR("not enough memory"); return ERROR_FAIL; } diff --git a/src/target/target.c b/src/target/target.c index 686aa5157..1879430a8 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5937,7 +5937,7 @@ static int jim_target_types(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_ERR; } Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0)); - for (unsigned x = 0; NULL != target_types[x]; x++) { + for (unsigned x = 0; target_types[x]; x++) { Jim_ListAppendElement(interp, Jim_GetResult(interp), Jim_NewStringObj(interp, target_types[x]->name, -1)); }