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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6352
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2021-07-03 21:47:55 +02:00
parent 3917823187
commit 0a1f904707
12 changed files with 20 additions and 20 deletions

View File

@ -55,7 +55,7 @@ static int arm_code_to_working_area(struct target *target,
*/ */
/* make sure we have a working area */ /* make sure we have a working area */
if (NULL == *area) { if (!*area) {
retval = target_alloc_working_area(target, size, area); retval = target_alloc_working_area(target, size, area);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_DEBUG("%s: no %d byte buffer", __func__, (int) size); LOG_DEBUG("%s: no %d byte buffer", __func__, (int) size);

View File

@ -180,7 +180,7 @@ static struct nand_device *get_nand_device_by_name(const char *name)
unsigned found = 0; unsigned found = 0;
struct nand_device *nand; 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) if (strcmp(nand->name, name) == 0)
return nand; return nand;
if (!flash_driver_name_matches(nand->controller->name, name)) if (!flash_driver_name_matches(nand->controller->name, name))

View File

@ -257,7 +257,7 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name)
unsigned found = 0; unsigned found = 0;
struct flash_bank *bank; 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) if (strcmp(bank->name, name) == 0)
return bank; return bank;
if (!flash_driver_name_matches(bank->driver->name, name)) if (!flash_driver_name_matches(bank->driver->name, name))

View File

@ -53,7 +53,7 @@ static const char hex_digits[] = {
void *buf_cpy(const void *from, void *_to, unsigned size) void *buf_cpy(const void *from, void *_to, unsigned size)
{ {
if (NULL == from || NULL == _to) if (!from || !_to)
return NULL; return NULL;
/* copy entire buffer */ /* copy entire buffer */

View File

@ -91,7 +91,7 @@ COMMAND_HANDLER(handle_adapter_list_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
command_print(CMD, "The following debug adapters are available:"); 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; const char *name = adapter_drivers[i]->name;
command_print(CMD, "%u: %s", i + 1, 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') if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
return ERROR_COMMAND_SYNTAX_ERROR; 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) if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
continue; continue;
if (NULL != adapter_drivers[i]->commands) { if (adapter_drivers[i]->commands) {
retval = register_commands(CMD_CTX, NULL, retval = register_commands(CMD_CTX, NULL,
adapter_drivers[i]->commands); adapter_drivers[i]->commands);
if (retval != ERROR_OK) if (retval != ERROR_OK)

View File

@ -67,7 +67,7 @@ void jtag_queue_command(struct jtag_command *cmd)
struct jtag_command **last_cmd = next_command_pointer; struct jtag_command **last_cmd = next_command_pointer;
assert(last_cmd); assert(last_cmd);
assert(NULL == *last_cmd); assert(!*last_cmd);
*last_cmd = cmd; *last_cmd = cmd;
/* store location where the next command pointer will be stored */ /* store location where the next command pointer will be stored */

View File

@ -785,7 +785,7 @@ static int vsllink_check_usb_strings(
char desc_string[256]; char desc_string[256];
int retval; int retval;
if (NULL != versaloon_interface.usb_setting.serialstring) { if (versaloon_interface.usb_setting.serialstring) {
retval = libusb_get_string_descriptor_ascii(usb_device_handle, retval = libusb_get_string_descriptor_ascii(usb_device_handle,
usb_desc->iSerialNumber, (unsigned char *)desc_string, usb_desc->iSerialNumber, (unsigned char *)desc_string,
sizeof(desc_string)); sizeof(desc_string));

View File

@ -472,7 +472,7 @@ static bool usb_read(unsigned char *buffer, int size, int *bytes_read,
{ {
int result; int result;
if (NULL == xds110.dev || NULL == buffer || NULL == bytes_read) if (!xds110.dev || !buffer || !bytes_read)
return false; return false;
/* Force a non-zero timeout to prevent blocking */ /* 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 result = LIBUSB_SUCCESS;
int retries = 0; int retries = 0;
if (NULL == xds110.dev || NULL == buffer) if (!xds110.dev || !buffer)
return false; return false;
result = libusb_bulk_transfer(xds110.dev, xds110.endpoint_out, buffer, 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; bool success;
if (NULL == dap_requests || NULL == dap_results) if (!dap_requests || !dap_results)
return false; return false;
xds110.write_payload[0] = OCD_DAP_REQUEST; 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; bool success;
if (NULL == scan_requests || NULL == scan_results) if (!scan_requests || !scan_results)
return false; return false;
xds110.write_payload[0] = OCD_SCAN_REQUEST; xds110.write_payload[0] = OCD_SCAN_REQUEST;

View File

@ -262,7 +262,7 @@ static struct command_context *setup_command_handler(Jim_Interp *interp)
&arm_tpiu_swo_register_commands, &arm_tpiu_swo_register_commands,
NULL 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); int retval = (*command_registrants[i])(cmd_ctx);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
command_done(cmd_ctx); command_done(cmd_ctx);

View File

@ -393,7 +393,7 @@ static int mqx_update_threads(
rtos->thread_details[i].exists = true; rtos->thread_details[i].exists = true;
/* set thread name */ /* set thread name */
rtos->thread_details[i].thread_name_str = malloc(strlen((void *)task_name) + 1); 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; return ERROR_FAIL;
strcpy(rtos->thread_details[i].thread_name_str, (void *)task_name); strcpy(rtos->thread_details[i].thread_name_str, (void *)task_name);
/* set thread extra info /* 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; extra_info_length += strlen((void *)state_name) + 7 + 13 + 8 + 15 + 8;
rtos->thread_details[i].extra_info_str = malloc(extra_info_length + 1); 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; return ERROR_FAIL;
snprintf(rtos->thread_details[i].extra_info_str, extra_info_length, snprintf(rtos->thread_details[i].extra_info_str, extra_info_length,
"State: %s, Address: 0x%" PRIx32 ", Error Code: %" PRIu32, "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[]) 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)); *symbol_list = calloc(ARRAY_SIZE(mqx_symbol_list), sizeof(struct symbol_table_elem));
if (NULL == *symbol_list) if (!*symbol_list)
return ERROR_FAIL; return ERROR_FAIL;
/* export required symbols */ /* export required symbols */
for (int i = 0; i < (int)(ARRAY_SIZE(mqx_symbol_list)); i++) for (int i = 0; i < (int)(ARRAY_SIZE(mqx_symbol_list)); i++)

View File

@ -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; 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); free(*arr);
*arr = calloc(1, new_byte_len); *arr = calloc(1, new_byte_len);
if (NULL == *arr) { if (!*arr) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -5937,7 +5937,7 @@ static int jim_target_types(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR; return JIM_ERR;
} }
Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0)); 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_ListAppendElement(interp, Jim_GetResult(interp),
Jim_NewStringObj(interp, target_types[x]->name, -1)); Jim_NewStringObj(interp, target_types[x]->name, -1));
} }