openocd: remove last NULL comparisons 39/6539/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 4 Sep 2021 21:01:09 +0000 (23:01 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 18 Sep 2021 15:22:30 +0000 (15:22 +0000)
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>
13 files changed:
src/jtag/drivers/jlink.c
src/rtos/linux.c
src/rtos/rtos.c
src/server/gdb_server.c
src/target/armv7a.c
src/target/armv7a_cache.c
src/target/armv7a_cache_l2x.c
src/target/armv8_cache.c
src/target/breakpoints.c
src/target/cortex_a.c
src/target/mips_m4k.c
src/target/smp.c
src/target/target.c

index 63bcda1f47ad31c323860a4a4644387fbf22b71c..319ca380a2b30b021776150725f046997ee74838 100644 (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");
index 11a55c43466493d9d4b1d6fd52f7b52f3886d357..84b4c6524d8abfd1e374fcf7001997cb05fc8326 100644 (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;
index 0e747e3e4c512158f02554b867a5996636e28c31..eaad5e50c9fd3432d305b32d8eb2ff0f3db1fc9c 100644 (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;
        }
index 015baa1d888a57c903767722668b11c73e74042a..a16b4ccbe901a4c5a0644baa566d41d906360fd1 100644 (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;
index 6de79c3892747ad1f04c888550f429dfd0affbca..2259fa560212b1d71c7e2c9469498d4b0d4279b1 100644 (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);
index fa6df2a273c2582bd673c9113761b0f2de85aa3d..4078fdde20607c5a2eb9de2e4f5f4ef4a287b289 100644 (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);
index 8ecdb008d7bbe9b0eb0b44a603dae726ee94555d..6b42fae53aa47a14497ab9db03aa477821bb6215 100644 (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);
index b668b84220fa28084b1c860834f6de64468d2e75..f05ac07cd6dca2c6b705008138fc9097bcac02ce 100644 (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);
index dfec75051a9f106f422c5a9acb85697d5b51809a..dd901ef25ba2b5e27ca56a62e75bc070e28bed8f 100644 (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;
index b1f22067fa794dbe4abbffc26ba9fa8f8456e024..241f2e68444b26f5d0d2c5398b691e85675f1b0c 100644 (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)) {
index cd06893511cfe3e6fb26e498d7705704b2951a92..ca4416981029932b2dd1b9d0a0e9360791bbdd64 100644 (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)) {
index 94c4da5a88510ed8a78e899599ebd7a378e29185..518f6e458531ab687e119d08c95c19695ed9b119 100644 (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);
index 7bace83f9ca34f2213401b06765139ad1f32bcc3..49f205a975cf27b1d46e1ff39066511b7def1554 100644 (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;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)