]> git.gag.com Git - fw/openocd/commitdiff
openocd: manually remove NULL comparisons
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 3 Jul 2021 20:10:55 +0000 (22:10 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 24 Jul 2021 09:38:19 +0000 (10:38 +0100)
For the remaining NULL comparisons, remove then manually.

While there, make more readable a loop, by moving the assigment
out of the loop condition.

Change-Id: I44193aaa95813156a3a79c16b80e1ad333dc1eaf
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6353
Tested-by: jenkins
src/flash/nor/tcl.c
src/helper/command.c
src/helper/fileio.c
src/jtag/aice/aice_usb.c
src/jtag/core.c
src/jtag/drivers/rlink.c
src/jtag/drivers/vsllink.c
src/server/telnet_server.c
src/target/target.c
src/target/target_request.c

index b078e9095ce83673de87c71b3d713ba3ade3c013..cbc64dcc40e0c36f23eacbc7afbacc3aa11ec6f6 100644 (file)
@@ -1276,7 +1276,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
        }
 
        /* check the flash bank name is unique */
-       if (get_flash_bank_by_name_noprobe(bank_name) != NULL) {
+       if (get_flash_bank_by_name_noprobe(bank_name)) {
                /* flash bank name already exists  */
                LOG_ERROR("flash bank name '%s' already exists", bank_name);
                return ERROR_FAIL;
index 681e8705e75d26688e489c73761e47705abb6b4c..42cb8c71ea8cba79a1efd643edc1a02e3192dcd5 100644 (file)
@@ -815,9 +815,9 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
 
        /* If the match string occurs anywhere, we print out
         * stuff for this command. */
-       bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
-               ((c->usage) && (strstr(c->usage, cmd_match) != NULL)) ||
-               ((c->help) && (strstr(c->help, cmd_match) != NULL));
+       bool is_match = strstr(c->cmd_name, cmd_match) ||
+               (c->usage && strstr(c->usage, cmd_match)) ||
+               (c->help && strstr(c->help, cmd_match));
 
        if (is_match) {
                if (c->usage && strlen(c->usage) > 0) {
index d544b8544d3dc313d09ab4cd6fb18f36a094f0ca..cec7dec52a650fad150678207327e032ecb90501 100644 (file)
@@ -208,7 +208,7 @@ int fileio_read_u32(struct fileio *fileio, uint32_t *data)
 
 static int fileio_local_fgets(struct fileio *fileio, size_t size, void *buffer)
 {
-       if (fgets(buffer, size, fileio->file) == NULL)
+       if (!fgets(buffer, size, fileio->file))
                return ERROR_FILEIO_OPERATION_FAILED;
 
        return ERROR_OK;
index 8d7f38bac1d0402b328062fa0851b48e620a3b21..53d283846d909b4e8197769e7c27670916d9f3ba 100644 (file)
@@ -2218,7 +2218,7 @@ static int aice_execute_custom_script(const char *script)
        if (!script_fd) {
                return ERROR_FAIL;
        } else {
-               while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
+               while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd)) {
                        /* execute operations */
                        set_op = false;
                        op_str = strstr(line_buffer, "set");
index 51c1228a329285f2f6966798f8a36b3caa1f2787..14062383f3327ed837397441f52e5454cfaec1ca 100644 (file)
@@ -1336,7 +1336,6 @@ out:
 static int jtag_validate_ircapture(void)
 {
        struct jtag_tap *tap;
-       int total_ir_length = 0;
        uint8_t *ir_test = NULL;
        struct scan_field field;
        uint64_t val;
@@ -1344,11 +1343,12 @@ static int jtag_validate_ircapture(void)
        int retval;
 
        /* when autoprobing, accommodate huge IR lengths */
-       for (tap = NULL, total_ir_length = 0;
-                       (tap = jtag_tap_next_enabled(tap)) != NULL;
-                       total_ir_length += tap->ir_length) {
+       int total_ir_length = 0;
+       for (tap = jtag_tap_next_enabled(NULL); tap; tap = jtag_tap_next_enabled(tap)) {
                if (tap->ir_length == 0)
                        total_ir_length += JTAG_IRLEN_MAX;
+               else
+                       total_ir_length += tap->ir_length;
        }
 
        /* increase length to add 2 bit sentinel after scan */
@@ -2008,7 +2008,7 @@ bool transport_is_jtag(void)
 
 int adapter_resets(int trst, int srst)
 {
-       if (get_current_transport() == NULL) {
+       if (!get_current_transport()) {
                LOG_ERROR("transport is not selected");
                return ERROR_FAIL;
        }
@@ -2065,7 +2065,7 @@ int adapter_assert_reset(void)
                           transport_is_dapdirect_jtag() || transport_is_dapdirect_swd() ||
                           transport_is_swim())
                return adapter_system_reset(1);
-       else if (get_current_transport() != NULL)
+       else if (get_current_transport())
                LOG_ERROR("reset is not supported on %s",
                        get_current_transport()->name);
        else
@@ -2082,7 +2082,7 @@ int adapter_deassert_reset(void)
                           transport_is_dapdirect_jtag() || transport_is_dapdirect_swd() ||
                           transport_is_swim())
                return adapter_system_reset(0);
-       else if (get_current_transport() != NULL)
+       else if (get_current_transport())
                LOG_ERROR("reset is not supported on %s",
                        get_current_transport()->name);
        else
index 8b6aa3ef4ceb578879f8d6bcbe4803fd4a336b8f..f75a38b5d22f02c36814edf8e1cfe0bb483dd057 100644 (file)
@@ -1148,11 +1148,8 @@ static int rlink_scan(struct jtag_command *cmd, enum scan_type type,
                byte_bits -= chunk_bits;
 
                if (type != SCAN_OUT) {
-                       if (dtc_queue_enqueue_reply(
-                                       type, buffer, scan_size, tdi_bit_offset,
-                                       chunk_bits,
-                                       cmd
-                               ) == NULL) {
+                       if (!dtc_queue_enqueue_reply(type, buffer, scan_size, tdi_bit_offset,
+                                       chunk_bits, cmd)) {
                                LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
                                exit(1);
                        }
@@ -1208,11 +1205,8 @@ static int rlink_scan(struct jtag_command *cmd, enum scan_type type,
                 * and one reply byte */
                dtc_queue_run_if_full(type == SCAN_IN ? 1 : 2, 1);
 
-               if (dtc_queue_enqueue_reply(
-                               type, buffer, scan_size, tdi_bit_offset,
-                               extra_bits,
-                               cmd
-                       ) == NULL) {
+               if (!dtc_queue_enqueue_reply(type, buffer, scan_size, tdi_bit_offset,
+                               extra_bits, cmd)) {
                        LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
                        exit(1);
                }
@@ -1260,11 +1254,8 @@ static int rlink_scan(struct jtag_command *cmd, enum scan_type type,
                        DTC_CMD_SHIFT_TMS_TDI_BIT_PAIR(1, (*tdi_p & tdi_mask), 0);
 
        } else {
-               if (dtc_queue_enqueue_reply(
-                               type, buffer, scan_size, tdi_bit_offset,
-                               1,
-                               cmd
-                               ) == NULL) {
+               if (!dtc_queue_enqueue_reply(type, buffer, scan_size, tdi_bit_offset,
+                               1, cmd)) {
                        LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
                        exit(1);
                }
index 6361ee0dad772b85a224ada7fc88a876b1608407..d298a9407f4bf333b24c1f6c63e73f9ef04eb53a 100644 (file)
@@ -803,7 +803,7 @@ static int vsllink_check_usb_strings(
        if (retval < 0)
                return ERROR_FAIL;
 
-       if (strstr(desc_string, "Versaloon") == NULL)
+       if (!strstr(desc_string, "Versaloon"))
                return ERROR_FAIL;
 
        return ERROR_OK;
index 97af3d97f1a7c5172998c95b6bf5ada318a105b4..697efa1a704e38dc7df9b78a33bdf13cbdeed87a 100644 (file)
@@ -159,7 +159,7 @@ static void telnet_load_history(struct telnet_connection *t_con)
 
        if (histfp) {
 
-               while (fgets(buffer, sizeof(buffer), histfp) != NULL) {
+               while (fgets(buffer, sizeof(buffer), histfp)) {
 
                        char *p = strchr(buffer, '\n');
                        if (p)
index 1879430a879119f0c01504eeedca79a90d0b7e62..37bbd376d1854f9d836eebf4ba900ff4a6d8b02c 100644 (file)
@@ -484,7 +484,7 @@ struct target *get_target(const char *id)
 
        /* try as tcltarget name */
        for (target = all_targets; target; target = target->next) {
-               if (target_name(target) == NULL)
+               if (!target_name(target))
                        continue;
                if (strcmp(id, target_name(target)) == 0)
                        return target;
index bea9346e10ef6e6525fcc6ed9dfbd8df1e6e3c94..562b046aadb04ac773ee861f8c5715168e4ba1b1 100644 (file)
@@ -262,7 +262,7 @@ COMMAND_HANDLER(handle_target_request_debugmsgs_command)
        }
 
        /* see if receiver is already registered */
-       if (find_debug_msg_receiver(CMD_CTX, target) != NULL)
+       if (find_debug_msg_receiver(CMD_CTX, target))
                receiving = 1;
 
        if (CMD_ARGC > 0) {