openocd: remove last NULL comparisons

The NULL pointers preceded by cast where not detected by the
scripting tools looking for NULL pointer comparison.

Remove them and, while there, further simplify the code and apply
the other coding style rules.

Change-Id: Ia7406122e07ef56ef311579ab0ee7ddb22c8e4b5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6539
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
This commit is contained in:
Antonio Borneo 2021-09-04 23:01:09 +02:00
parent ea562985b5
commit 79800db98a
13 changed files with 33 additions and 32 deletions

View File

@ -573,7 +573,7 @@ static int jlink_open_device(uint32_t ifaces, bool *found_device)
return ERROR_JTAG_INIT_FAILED;
}
use_usb_location = (jtag_usb_get_location() != NULL);
use_usb_location = !!jtag_usb_get_location();
if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) {
LOG_ERROR("Multiple devices found, specify the desired device");

View File

@ -195,13 +195,12 @@ static int linux_os_thread_reg_list(struct rtos *rtos,
found = 0;
do {
if (head->target->coreid == next->core_id) {
target = head->target;
found = 1;
} else
head = head->next;
} while ((head != (struct target_list *)NULL) && (found == 0));
break;
}
head = head->next;
} while (head);
if (found == 0) {
LOG_ERROR
@ -414,7 +413,7 @@ static int get_current(struct target *target, int create)
ctt = ctt->next;
}
while (head != (struct target_list *)NULL) {
while (head) {
struct reg **reg_list;
int reg_list_size;
int retval;
@ -1397,7 +1396,7 @@ static int linux_os_smp_init(struct target *target)
struct current_thread *ct;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
if (head->target->rtos != rtos) {
struct linux_os *smp_os_linux =
(struct linux_os *)head->target->rtos->rtos_specific_params;

View File

@ -234,7 +234,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s
uint64_t addr = 0;
size_t reply_len;
char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for null-termination */
struct symbol_table_elem *next_sym = NULL;
struct symbol_table_elem *next_sym;
struct target *target = get_target_from_connection(connection);
struct rtos *os = target->rtos;
@ -272,7 +272,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s
next_sym = next_symbol(os, cur_sym, addr);
/* Should never happen unless the debugger misbehaves */
if (next_sym == NULL) {
if (!next_sym) {
LOG_WARNING("RTOS: Debugger sent us qSymbol with '%s' that we did not ask for", cur_sym);
goto done;
}

View File

@ -3006,8 +3006,10 @@ static bool gdb_handle_vrun_packet(struct connection *connection, const char *pa
free(next_hex_encoded_field(&parse, ';'));
char *cmdline = next_hex_encoded_field(&parse, ';');
char *arg;
while (cmdline && (arg = next_hex_encoded_field(&parse, ';')) != NULL) {
while (cmdline) {
char *arg = next_hex_encoded_field(&parse, ';');
if (!arg)
break;
char *new_cmdline = alloc_printf("%s %s", cmdline, arg);
free(cmdline);
free(arg);
@ -3549,7 +3551,7 @@ static int gdb_target_start(struct target *target, const char *port)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if (curr != target)
curr->gdb_service = gdb_service;

View File

@ -207,7 +207,7 @@ static int armv7a_l2x_cache_init(struct target *target, uint32_t base, uint32_t
armv7a->armv7a_mmu.armv7a_cache.outer_cache = l2x_cache;
/* initialize all target in this cluster (smp target)
* l2 cache must be configured after smp declaration */
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if (curr != target) {
armv7a = target_to_armv7a(curr);

View File

@ -140,7 +140,7 @@ int armv7a_cache_auto_flush_all_data(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if (curr->state == TARGET_HALTED)
retval = armv7a_l1_d_cache_clean_inval_all(curr);

View File

@ -210,7 +210,7 @@ static int armv7a_l2x_cache_init(struct target *target, uint32_t base, uint32_t
/* initialize all targets in this cluster (smp target)
* l2 cache must be configured after smp declaration */
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if (curr != target) {
armv7a = target_to_armv7a(curr);

View File

@ -252,7 +252,7 @@ static int armv8_flush_all_data(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if (curr->state == TARGET_HALTED) {
LOG_INFO("Wait flushing data l1 on core %" PRId32, curr->coreid);

View File

@ -224,7 +224,7 @@ int breakpoint_add(struct target *target,
if (type == BKPT_SOFT)
return breakpoint_add_internal(head->target, address, length, type);
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
retval = breakpoint_add_internal(curr, address, length, type);
if (retval != ERROR_OK)
@ -247,7 +247,7 @@ int context_breakpoint_add(struct target *target,
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
retval = context_breakpoint_add_internal(curr, asid, length, type);
if (retval != ERROR_OK)
@ -271,7 +271,7 @@ int hybrid_breakpoint_add(struct target *target,
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
retval = hybrid_breakpoint_add_internal(curr, address, asid, length, type);
if (retval != ERROR_OK)
@ -347,7 +347,7 @@ void breakpoint_remove(struct target *target, target_addr_t address)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
num_breakpoints += breakpoint_remove_internal(curr, address);
head = head->next;
@ -365,7 +365,7 @@ void breakpoint_remove_all(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
breakpoint_remove_all_internal(curr);
head = head->next;
@ -389,7 +389,7 @@ void breakpoint_clear_target(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
breakpoint_clear_target_internal(curr);
head = head->next;

View File

@ -641,7 +641,7 @@ static struct target *get_cortex_a(struct target *target, int32_t coreid)
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if ((curr->coreid == coreid) && (curr->state == TARGET_HALTED))
return curr;
@ -657,7 +657,7 @@ static int cortex_a_halt_smp(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if ((curr != target) && (curr->state != TARGET_HALTED)
&& target_was_examined(curr))
@ -953,7 +953,7 @@ static int cortex_a_restore_smp(struct target *target, int handle_breakpoints)
struct target *curr;
target_addr_t address;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if ((curr != target) && (curr->state != TARGET_RUNNING)
&& target_was_examined(curr)) {

View File

@ -131,7 +131,7 @@ static struct target *get_mips_m4k(struct target *target, int32_t coreid)
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
curr = head->target;
if ((curr->coreid == coreid) && (curr->state == TARGET_HALTED))
return curr;
@ -146,7 +146,7 @@ static int mips_m4k_halt_smp(struct target *target)
struct target_list *head;
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
int ret = ERROR_OK;
curr = head->target;
if ((curr != target) && (curr->state != TARGET_HALTED))
@ -417,7 +417,7 @@ static int mips_m4k_restore_smp(struct target *target, uint32_t address, int han
struct target *curr;
head = target->head;
while (head != (struct target_list *)NULL) {
while (head) {
int ret = ERROR_OK;
curr = head->target;
if ((curr != target) && (curr->state != TARGET_RUNNING)) {

View File

@ -137,7 +137,7 @@ COMMAND_HANDLER(handle_smp_gdb_command)
int retval = ERROR_OK;
struct target_list *head;
head = target->head;
if (head != (struct target_list *)NULL) {
if (head) {
if (CMD_ARGC == 1) {
int coreid = 0;
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], coreid);

View File

@ -5999,7 +5999,7 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
new = malloc(sizeof(struct target_list));
new->target = target;
new->next = (struct target_list *)NULL;
if (head == (struct target_list *)NULL) {
if (!head) {
head = new;
curr = head;
} else {
@ -6011,7 +6011,7 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* now parse the list of cpu and put the target in smp mode*/
curr = head;
while (curr != (struct target_list *)NULL) {
while (curr) {
target = curr->target;
target->smp = 1;
target->head = head;