openocd: remove NULL comparisons with checkpatch [1/2]

Patch generated automatically through the new checkpatch with
flags "--types COMPARISON_TO_NULL --fix-inplace".
This only fixes the comparisons
	if (symbol == NULL)
	if (symbol != NULL)
The case of NULL on the left side of the comparison is not tested.

Some automatic fix is incorrect and has been massaged by hands:
	-	if (*psig == NULL)
	+	if (*!psig)
changed as
	+	if (!*psig)

Change-Id: If4a1e2b4e547e223532e8e3d9da89bf9cb382ce6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6351
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2021-07-03 21:29:32 +02:00
parent 08ee7bb982
commit 3917823187
71 changed files with 181 additions and 181 deletions

View File

@@ -682,7 +682,7 @@ int nand_write_page(struct nand_device *nand, uint32_t page,
if (nand->blocks[block].is_erased == 1)
nand->blocks[block].is_erased = 0;
if (nand->use_raw || nand->controller->write_page == NULL)
if (nand->use_raw || !nand->controller->write_page)
return nand_write_page_raw(nand, page, data, data_size, oob, oob_size);
else
return nand->controller->write_page(nand, page, data, data_size, oob, oob_size);
@@ -695,7 +695,7 @@ int nand_read_page(struct nand_device *nand, uint32_t page,
if (!nand->device)
return ERROR_NAND_DEVICE_NOT_PROBED;
if (nand->use_raw || nand->controller->read_page == NULL)
if (nand->use_raw || !nand->controller->read_page)
return nand_read_page_raw(nand, page, data, data_size, oob, oob_size);
else
return nand->controller->read_page(nand, page, data, data_size, oob, oob_size);
@@ -769,7 +769,7 @@ int nand_read_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
{
int retval = ERROR_NAND_NO_BUFFER;
if (nand->controller->read_block_data != NULL)
if (nand->controller->read_block_data)
retval = (nand->controller->read_block_data)(nand, data, size);
if (retval == ERROR_NAND_NO_BUFFER) {
@@ -809,7 +809,7 @@ int nand_write_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
{
int retval = ERROR_NAND_NO_BUFFER;
if (nand->controller->write_block_data != NULL)
if (nand->controller->write_block_data)
retval = (nand->controller->write_block_data)(nand, data, size);
if (retval == ERROR_NAND_NO_BUFFER) {

View File

@@ -3545,7 +3545,7 @@ COMMAND_HANDLER(sam3_handle_info_command)
int r;
/* bank0 must exist before we can do anything */
if (chip->details.bank[0].bank == NULL) {
if (!chip->details.bank[0].bank) {
x = 0;
need_define:
command_print(CMD,
@@ -3571,7 +3571,7 @@ need_define:
if (!(chip->details.bank[x].present))
continue;
if (chip->details.bank[x].bank == NULL)
if (!chip->details.bank[x].bank)
goto need_define;
if (chip->details.bank[x].probed)
@@ -3606,7 +3606,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command)
return ERROR_TARGET_NOT_HALTED;
}
if (chip->details.bank[0].bank == NULL) {
if (!chip->details.bank[0].bank) {
command_print(CMD, "Bank0 must be defined first via: flash bank %s ...",
at91sam3_flash.name);
return ERROR_FAIL;

View File

@@ -3092,7 +3092,7 @@ COMMAND_HANDLER(sam4_handle_info_command)
int r;
/* bank0 must exist before we can do anything */
if (chip->details.bank[0].bank == NULL) {
if (!chip->details.bank[0].bank) {
x = 0;
need_define:
command_print(CMD,
@@ -3118,7 +3118,7 @@ need_define:
if (!(chip->details.bank[x].present))
continue;
if (chip->details.bank[x].bank == NULL)
if (!chip->details.bank[x].bank)
goto need_define;
if (chip->details.bank[x].probed)
@@ -3153,7 +3153,7 @@ COMMAND_HANDLER(sam4_handle_gpnvm_command)
return ERROR_TARGET_NOT_HALTED;
}
if (chip->details.bank[0].bank == NULL) {
if (!chip->details.bank[0].bank) {
command_print(CMD, "Bank0 must be defined first via: flash bank %s ...",
at91sam4_flash.name);
return ERROR_FAIL;

View File

@@ -1040,7 +1040,7 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command)
return ERROR_COMMAND_SYNTAX_ERROR;
bank = get_flash_bank_by_num_noprobe(0);
if (bank == NULL)
if (!bank)
return ERROR_FLASH_BANK_INVALID;
if (strcmp(bank->driver->name, "at91sam7")) {
command_print(CMD, "not an at91sam7 flash bank '%s'", CMD_ARGV[0]);

View File

@@ -1064,7 +1064,7 @@ static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value)
char *check = NULL;
*value = strtoull(&(CMD_ARGV[num][2]), &check, 16);
if ((value == 0 && errno == ERANGE) ||
check == NULL || *check != 0) {
!check || *check != 0) {
command_print(CMD, "Invalid 64-bit hex value in argument %d.",
num + 1);
return ERROR_COMMAND_SYNTAX_ERROR;

View File

@@ -70,7 +70,7 @@ int flash_driver_protect(struct flash_bank *bank, int set, unsigned int first,
/* force "set" to 0/1 */
set = !!set;
if (bank->driver->protect == NULL) {
if (!bank->driver->protect) {
LOG_ERROR("Flash protection is not supported.");
return ERROR_FLASH_OPER_UNSUPPORTED;
}
@@ -491,7 +491,7 @@ static int flash_iterate_address_range_inner(struct target *target,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
if (c->prot_blocks == NULL || c->num_prot_blocks == 0) {
if (!c->prot_blocks || c->num_prot_blocks == 0) {
/* flash driver does not define protect blocks, use sectors instead */
iterate_protect_blocks = false;
}

View File

@@ -172,7 +172,7 @@ static int jtagspi_probe(struct flash_bank *bank)
free(bank->sectors);
info->probed = false;
if (bank->target->tap == NULL) {
if (!bank->target->tap) {
LOG_ERROR("Target has no JTAG tap");
return ERROR_FAIL;
}

View File

@@ -714,7 +714,7 @@ static int pic32mx_probe(struct flash_bank *bank)
}
/* Check for PIC32mx1xx/2xx */
for (i = 0; pic32mx_devs[i].name != NULL; i++) {
for (i = 0; pic32mx_devs[i].name; i++) {
if (pic32mx_devs[i].devid == (device_id & 0x0fffffff)) {
if ((pic32mx_devs[i].name[0] == '1') || (pic32mx_devs[i].name[0] == '2'))
pic32mx_info->dev_type = (pic32mx_devs[i].name[1] == '7') ? MX_17X_27X : MX_1XX_2XX;
@@ -819,14 +819,14 @@ static int pic32mx_info(struct flash_bank *bank, struct command_invocation *cmd)
}
int i;
for (i = 0; pic32mx_devs[i].name != NULL; i++) {
for (i = 0; pic32mx_devs[i].name; i++) {
if (pic32mx_devs[i].devid == (device_id & 0x0fffffff)) {
command_print_sameline(cmd, "PIC32MX%s", pic32mx_devs[i].name);
break;
}
}
if (pic32mx_devs[i].name == NULL)
if (!pic32mx_devs[i].name)
command_print_sameline(cmd, "Unknown");
command_print_sameline(cmd, " Ver: 0x%02x",

View File

@@ -99,7 +99,7 @@ COMMAND_HANDLER(handle_flash_info_command)
/* If the driver does not implement protection, we show the default
* state of is_protected array - usually protection state unknown */
if (p->driver->protect_check == NULL) {
if (!p->driver->protect_check) {
retval = ERROR_FLASH_OPER_UNSUPPORTED;
} else {
/* We must query the hardware to avoid printing stale information! */
@@ -148,7 +148,7 @@ COMMAND_HANDLER(handle_flash_info_command)
protect_state);
}
if (p->driver->info != NULL) {
if (p->driver->info) {
/* Let the flash driver print extra custom info */
retval = p->driver->info(p, CMD);
command_print_sameline(CMD, "\n");

View File

@@ -93,7 +93,7 @@ static int virtual_protect_check(struct flash_bank *bank)
if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED;
if (master_bank->driver->protect_check == NULL)
if (!master_bank->driver->protect_check)
return ERROR_FLASH_OPER_UNSUPPORTED;
/* call master handler */

View File

@@ -602,7 +602,7 @@ static int xcf_probe(struct flash_bank *bank)
free(bank->sectors);
priv->probed = false;
if (bank->target->tap == NULL) {
if (!bank->target->tap) {
LOG_ERROR("Target has no JTAG tap");
return ERROR_FAIL;
}

View File

@@ -221,7 +221,7 @@ static char **script_command_args_alloc(
int len;
const char *w = Jim_GetString(argv[i], &len);
words[i] = strdup(w);
if (words[i] == NULL) {
if (!words[i]) {
script_command_args_free(words, i);
return NULL;
}
@@ -501,7 +501,7 @@ void command_print_sameline(struct command_invocation *cmd, const char *format,
va_start(ap, format);
string = alloc_vprintf(format, ap);
if (string != NULL && cmd) {
if (string && cmd) {
/* we want this collected in the log + we also want to pick it up as a tcl return
* value.
*
@@ -524,7 +524,7 @@ void command_print(struct command_invocation *cmd, const char *format, ...)
va_start(ap, format);
string = alloc_vprintf(format, ap);
if (string != NULL && cmd) {
if (string && cmd) {
strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one
*char longer */
/* we want this collected in the log + we also want to pick it up as a tcl return

View File

@@ -230,7 +230,7 @@ COMMAND_HANDLER(handle_debug_level_command)
COMMAND_HANDLER(handle_log_output_command)
{
if (CMD_ARGC == 0 || (CMD_ARGC == 1 && strcmp(CMD_ARGV[0], "default") == 0)) {
if (log_output != stderr && log_output != NULL) {
if (log_output != stderr && log_output) {
/* Close previous log file, if it was open and wasn't stderr. */
fclose(log_output);
}
@@ -244,7 +244,7 @@ COMMAND_HANDLER(handle_log_output_command)
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
return ERROR_FAIL;
}
if (log_output != stderr && log_output != NULL) {
if (log_output != stderr && log_output) {
/* Close previous log file, if it was open and wasn't stderr. */
fclose(log_output);
}

View File

@@ -145,7 +145,7 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time
struct timeval tvslice;
int retcode;
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
#define SAFE_FD_ISSET(fd, set) (set && FD_ISSET(fd, set))
/* calculate how long we need to wait in milliseconds */
if (!tv)

View File

@@ -218,7 +218,7 @@ static void jtag_tap_add(struct jtag_tap *t)
unsigned jtag_num_taps = 0;
struct jtag_tap **tap = &__jtag_all_taps;
while (*tap != NULL) {
while (*tap) {
jtag_num_taps++;
tap = &(*tap)->next_tap;
}
@@ -429,7 +429,7 @@ static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(
jtag_add_scan(active, in_num_fields, in_fields, state);
for (int i = 0; i < in_num_fields; i++) {
if ((in_fields[i].check_value != NULL) && (in_fields[i].in_value != NULL)) {
if ((in_fields[i].check_value) && (in_fields[i].in_value)) {
jtag_add_callback4(jtag_check_value_mask_callback,
(jtag_callback_data_t)in_fields[i].in_value,
(jtag_callback_data_t)in_fields[i].check_value,

View File

@@ -209,7 +209,7 @@ static int at91rm9200_init(void)
cur_device = devices;
if (at91rm9200_device == NULL || at91rm9200_device[0] == 0) {
if (!at91rm9200_device || at91rm9200_device[0] == 0) {
at91rm9200_device = "rea_ecr";
LOG_WARNING("No at91rm9200 device specified, using default 'rea_ecr'");
}

View File

@@ -1513,7 +1513,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int
s_offset + offset,
tms,
tdo_buffer,
tdo_buffer == NULL ? 0 : (tdo_buffer_offset + offset)
!tdo_buffer ? 0 : (tdo_buffer_offset + offset)
);
}
LOG_DEBUG_IO("END JTAG SEQ SPLIT");
@@ -1530,7 +1530,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int
/* control byte */
queued_seq_buf[queued_seq_buf_end] =
(tms ? DAP_JTAG_SEQ_TMS : 0) |
(tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) |
(tdo_buffer ? DAP_JTAG_SEQ_TDO : 0) |
(s_len == 64 ? 0 : s_len);
if (sequence)

View File

@@ -82,7 +82,7 @@ int interface_jtag_add_ir_scan(struct jtag_tap *active,
/* loop over all enabled TAPs */
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap; tap = jtag_tap_next_enabled(tap)) {
/* search the input field list for fields for the current TAP */
if (tap == active) {
@@ -122,7 +122,7 @@ int interface_jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields,
size_t bypass_devices = 0;
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap; tap = jtag_tap_next_enabled(tap)) {
if (tap->bypass)
bypass_devices++;
}
@@ -145,7 +145,7 @@ int interface_jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields,
/* loop over all enabled TAPs */
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap; tap = jtag_tap_next_enabled(tap)) {
/* if TAP is not bypassed insert matching input fields */
if (!tap->bypass) {
@@ -369,7 +369,7 @@ int interface_jtag_execute_queue(void)
int retval = default_interface_jtag_execute_queue();
if (retval == ERROR_OK) {
struct jtag_callback_entry *entry;
for (entry = jtag_callback_queue_head; entry != NULL; entry = entry->next) {
for (entry = jtag_callback_queue_head; entry; entry = entry->next) {
retval = entry->callback(entry->data0, entry->data1, entry->data2, entry->data3);
if (retval != ERROR_OK)
break;

View File

@@ -150,11 +150,11 @@ static struct signal *create_signal(const char *name)
psig = &(*psig)->next;
*psig = calloc(1, sizeof(**psig));
if (*psig == NULL)
if (!*psig)
return NULL;
(*psig)->name = strdup(name);
if ((*psig)->name == NULL) {
if (!(*psig)->name) {
free(*psig);
*psig = NULL;
}
@@ -1068,7 +1068,7 @@ static int ftdi_swd_init(void)
swd_cmd_queue_alloced = 10;
swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue));
return swd_cmd_queue != NULL ? ERROR_OK : ERROR_FAIL;
return swd_cmd_queue ? ERROR_OK : ERROR_FAIL;
}
static void ftdi_swd_swdio_en(bool enable)
@@ -1143,7 +1143,7 @@ static int ftdi_swd_run_queue(void)
goto skip;
}
if (swd_cmd_queue[i].dst != NULL)
if (swd_cmd_queue[i].dst)
*swd_cmd_queue[i].dst = data;
}
}

View File

@@ -238,7 +238,7 @@ static int jtag_dpi_execute_queue(void)
struct jtag_command *cmd;
int ret = ERROR_OK;
for (cmd = jtag_command_queue; ret == ERROR_OK && cmd != NULL;
for (cmd = jtag_command_queue; ret == ERROR_OK && cmd;
cmd = cmd->next) {
switch (cmd->type) {
case JTAG_RUNTEST:

Some files were not shown because too many files have changed in this diff Show More