diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2020-08-17 10:05:11 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-09-05 18:42:20 +0100 |
commit | 24db985f602bbe21ee4d10147937ed897f28a555 (patch) | |
tree | 0829fa6f4c41653c76ba61d6b0549e27b3b4ff81 | |
parent | a098a14eb53131871469a9c32b206b0dc55ef237 (diff) | |
download | riscv-openocd-24db985f602bbe21ee4d10147937ed897f28a555.zip riscv-openocd-24db985f602bbe21ee4d10147937ed897f28a555.tar.gz riscv-openocd-24db985f602bbe21ee4d10147937ed897f28a555.tar.bz2 |
jtag: avoid checking for non NULL pointer to free it
The function free() can be called with a NULL pointer as argument,
no need to check the argument before. If the pointer is NULL, no
operation is performed by free().
Remove the occurrences of pattern:
if (ptr)
free(ptr);
Change-Id: I2938e333bd1eac5218bd67aefb9d8f373da017a8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5810
Tested-by: jenkins
-rw-r--r-- | src/jtag/aice/aice_usb.c | 12 | ||||
-rw-r--r-- | src/jtag/drivers/amt_jtagaccel.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/arm-jtag-ew.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/bitbang.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/buspirate.c | 6 | ||||
-rw-r--r-- | src/jtag/drivers/ft232r.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/ftdi.c | 6 | ||||
-rw-r--r-- | src/jtag/drivers/gw16012.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/jtag_usb_common.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/jtag_vpi.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/kitprog.c | 17 | ||||
-rw-r--r-- | src/jtag/drivers/mpsse.c | 9 | ||||
-rw-r--r-- | src/jtag/drivers/opendous.c | 27 | ||||
-rw-r--r-- | src/jtag/drivers/openjtag.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/parport.c | 6 | ||||
-rw-r--r-- | src/jtag/drivers/presto.c | 9 | ||||
-rw-r--r-- | src/jtag/drivers/ti_icdi_usb.c | 9 | ||||
-rw-r--r-- | src/jtag/drivers/usb_blaster/usb_blaster.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/usbprog.c | 3 | ||||
-rw-r--r-- | src/jtag/drivers/versaloon/versaloon.c | 13 | ||||
-rw-r--r-- | src/jtag/drivers/vsllink.c | 23 | ||||
-rw-r--r-- | src/jtag/drivers/xlnx-pcie-xvc.c | 9 | ||||
-rw-r--r-- | src/jtag/tcl.c | 6 |
23 files changed, 60 insertions, 122 deletions
diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c index 5a200eb..7144632 100644 --- a/src/jtag/aice/aice_usb.c +++ b/src/jtag/aice/aice_usb.c @@ -2537,15 +2537,9 @@ static int aice_usb_close(void) { jtag_libusb_close(aice_handler.usb_handle); - if (custom_srst_script) - free(custom_srst_script); - - if (custom_trst_script) - free(custom_trst_script); - - if (custom_restart_script) - free(custom_restart_script); - + free(custom_srst_script); + free(custom_trst_script); + free(custom_restart_script); return ERROR_OK; } diff --git a/src/jtag/drivers/amt_jtagaccel.c b/src/jtag/drivers/amt_jtagaccel.c index 81721cb..e9ff8df 100644 --- a/src/jtag/drivers/amt_jtagaccel.c +++ b/src/jtag/drivers/amt_jtagaccel.c @@ -370,8 +370,7 @@ static int amt_jtagaccel_execute_queue(void) amt_jtagaccel_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); + free(buffer); break; case JTAG_SLEEP: LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us); diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index 60b1195..40d52ac 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -664,8 +664,7 @@ static int armjtagew_tap_execute(void) return ERROR_JTAG_QUEUE_FAILED; } - if (pending_scan_result->buffer != NULL) - free(pending_scan_result->buffer); + free(pending_scan_result->buffer); } } else { LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d", diff --git a/src/jtag/drivers/bitbang.c b/src/jtag/drivers/bitbang.c index b33e87f..df1d601 100644 --- a/src/jtag/drivers/bitbang.c +++ b/src/jtag/drivers/bitbang.c @@ -358,8 +358,7 @@ int bitbang_execute_queue(void) return ERROR_FAIL; if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); + free(buffer); break; case JTAG_SLEEP: LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us); diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 2483b43..dc38c5d 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -352,10 +352,8 @@ static int buspirate_quit(void) buspirate_serial_close(buspirate_fd); - if (buspirate_port) { - free(buspirate_port); - buspirate_port = NULL; - } + free(buspirate_port); + buspirate_port = NULL; return ERROR_OK; } diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c index 3c54809..d97db56 100644 --- a/src/jtag/drivers/ft232r.c +++ b/src/jtag/drivers/ft232r.c @@ -886,8 +886,7 @@ static int syncbb_execute_queue(void) syncbb_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); + free(buffer); break; case JTAG_SLEEP: diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index d2b97b9..4fa83ae 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -709,8 +709,7 @@ static int ftdi_quit(void) COMMAND_HANDLER(ftdi_handle_device_desc_command) { if (CMD_ARGC == 1) { - if (ftdi_device_desc) - free(ftdi_device_desc); + free(ftdi_device_desc); ftdi_device_desc = strdup(CMD_ARGV[0]); } else { LOG_ERROR("expected exactly one argument to ftdi_device_desc <description>"); @@ -722,8 +721,7 @@ COMMAND_HANDLER(ftdi_handle_device_desc_command) COMMAND_HANDLER(ftdi_handle_serial_command) { if (CMD_ARGC == 1) { - if (ftdi_serial) - free(ftdi_serial); + free(ftdi_serial); ftdi_serial = strdup(CMD_ARGV[0]); } else { return ERROR_COMMAND_SYNTAX_ERROR; diff --git a/src/jtag/drivers/gw16012.c b/src/jtag/drivers/gw16012.c index cad2e1b..ef4b5d9 100644 --- a/src/jtag/drivers/gw16012.c +++ b/src/jtag/drivers/gw16012.c @@ -327,8 +327,7 @@ static int gw16012_execute_queue(void) gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); + free(buffer); break; case JTAG_SLEEP: LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us); diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index 6337272..969ea84 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -23,8 +23,7 @@ void jtag_usb_set_location(const char *location) JTAG_USB_MAX_LOCATION_LENGTH) LOG_WARNING("usb location string is too long!!\n"); - if (jtag_usb_location) - free(jtag_usb_location); + free(jtag_usb_location); jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH); } diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index 789d3a4..32a43f8 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -439,8 +439,7 @@ static int jtag_vpi_scan(struct scan_command *cmd) if (retval != ERROR_OK) return retval; - if (buf) - free(buf); + free(buf); if (cmd->end_state != TAP_DRSHIFT) { retval = jtag_vpi_state_move(cmd->end_state); diff --git a/src/jtag/drivers/kitprog.c b/src/jtag/drivers/kitprog.c index 4f38d19..5538bcd 100644 --- a/src/jtag/drivers/kitprog.c +++ b/src/jtag/drivers/kitprog.c @@ -227,18 +227,11 @@ static int kitprog_quit(void) { kitprog_usb_close(); - if (kitprog_handle->packet_buffer != NULL) - free(kitprog_handle->packet_buffer); - if (kitprog_handle->serial != NULL) - free(kitprog_handle->serial); - if (kitprog_handle != NULL) - free(kitprog_handle); - - if (kitprog_serial != NULL) - free(kitprog_serial); - - if (pending_transfers != NULL) - free(pending_transfers); + free(kitprog_handle->packet_buffer); + free(kitprog_handle->serial); + free(kitprog_handle); + free(kitprog_serial); + free(pending_transfers); return ERROR_OK; } diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 7488d9d..fe8b6b8 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -404,13 +404,10 @@ void mpsse_close(struct mpsse_ctx *ctx) if (ctx->usb_ctx) libusb_exit(ctx->usb_ctx); bit_copy_discard(&ctx->read_queue); - if (ctx->write_buffer) - free(ctx->write_buffer); - if (ctx->read_buffer) - free(ctx->read_buffer); - if (ctx->read_chunk) - free(ctx->read_chunk); + free(ctx->write_buffer); + free(ctx->read_buffer); + free(ctx->read_chunk); free(ctx); } diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index bccd3dd..f0e4f56 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -386,25 +386,17 @@ static int opendous_quit(void) { opendous_usb_close(opendous_jtag_handle); - if (usb_out_buffer) { - free(usb_out_buffer); - usb_out_buffer = NULL; - } + free(usb_out_buffer); + usb_out_buffer = NULL; - if (usb_in_buffer) { - free(usb_in_buffer); - usb_in_buffer = NULL; - } + free(usb_in_buffer); + usb_in_buffer = NULL; - if (pending_scan_results_buffer) { - free(pending_scan_results_buffer); - pending_scan_results_buffer = NULL; - } + free(pending_scan_results_buffer); + pending_scan_results_buffer = NULL; - if (opendous_type) { - free(opendous_type); - opendous_type = NULL; - } + free(opendous_type); + opendous_type = NULL; return ERROR_OK; } @@ -697,8 +689,7 @@ int opendous_tap_execute(void) return ERROR_JTAG_QUEUE_FAILED; } - if (pending_scan_result->buffer != NULL) - free(pending_scan_result->buffer); + free(pending_scan_result->buffer); } opendous_tap_init(); diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 7eab5c1..2cf5751 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -591,8 +591,7 @@ static int openjtag_execute_tap_queue(void) #endif jtag_read_buffer(buffer, openjtag_scan_result_buffer[res_count].command); - if (openjtag_scan_result_buffer[res_count].buffer) - free(openjtag_scan_result_buffer[res_count].buffer); + free(openjtag_scan_result_buffer[res_count].buffer); res_count++; } diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c index b3abd12..b203c82 100644 --- a/src/jtag/drivers/parport.c +++ b/src/jtag/drivers/parport.c @@ -392,10 +392,8 @@ static int parport_quit(void) parport_write_data(); } - if (parport_cable) { - free(parport_cable); - parport_cable = NULL; - } + free(parport_cable); + parport_cable = NULL; return ERROR_OK; } diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c index 4046b22..6c3a187 100644 --- a/src/jtag/drivers/presto.c +++ b/src/jtag/drivers/presto.c @@ -511,8 +511,7 @@ static char *presto_serial; COMMAND_HANDLER(presto_handle_serial_command) { if (CMD_ARGC == 1) { - if (presto_serial) - free(presto_serial); + free(presto_serial); presto_serial = strdup(CMD_ARGV[0]); } else return ERROR_COMMAND_SYNTAX_ERROR; @@ -553,10 +552,8 @@ static int presto_jtag_quit(void) presto_close(); LOG_INFO("PRESTO closed"); - if (presto_serial) { - free(presto_serial); - presto_serial = NULL; - } + free(presto_serial); + presto_serial = NULL; return ERROR_OK; } diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c index f316c82..d276e58 100644 --- a/src/jtag/drivers/ti_icdi_usb.c +++ b/src/jtag/drivers/ti_icdi_usb.c @@ -662,14 +662,9 @@ static int icdi_usb_close(void *handle) if (h->usb_ctx) libusb_exit(h->usb_ctx); - if (h->read_buffer) - free(h->read_buffer); - - if (h->write_buffer) - free(h->write_buffer); - + free(h->read_buffer); + free(h->write_buffer); free(handle); - return ERROR_OK; } diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 3c9c3a7..9648ba2 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -736,8 +736,7 @@ static int ublast_scan(struct scan_command *cmd) ublast_queue_tdi(buf, scan_bits, type); ret = jtag_read_buffer(buf, cmd); - if (buf) - free(buf); + free(buf); /* * ublast_queue_tdi sends the last bit with TMS=1. We are therefore * already in Exit1-DR/IR and have to skip the first step on our way diff --git a/src/jtag/drivers/usbprog.c b/src/jtag/drivers/usbprog.c index dd7dcdb..627e465 100644 --- a/src/jtag/drivers/usbprog.c +++ b/src/jtag/drivers/usbprog.c @@ -137,8 +137,7 @@ static int usbprog_execute_queue(void) usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) return ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); + free(buffer); break; case JTAG_SLEEP: LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us); diff --git a/src/jtag/drivers/versaloon/versaloon.c b/src/jtag/drivers/versaloon/versaloon.c index 35a0def..8efe443 100644 --- a/src/jtag/drivers/versaloon/versaloon.c +++ b/src/jtag/drivers/versaloon/versaloon.c @@ -299,14 +299,11 @@ RESULT versaloon_fini(void) versaloon_usb_device_handle = NULL; - if (versaloon_buf != NULL) { - free(versaloon_buf); - versaloon_buf = NULL; - } - if (versaloon_cmd_buf != NULL) { - free(versaloon_cmd_buf); - versaloon_cmd_buf = NULL; - } + free(versaloon_buf); + versaloon_buf = NULL; + + free(versaloon_cmd_buf); + versaloon_cmd_buf = NULL; } return ERROR_OK; diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 6f2296e..9aaed36 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -245,18 +245,14 @@ static int vsllink_speed_div(int jtag_speed, int *khz) static void vsllink_free_buffer(void) { - if (tdi_buffer != NULL) { - free(tdi_buffer); - tdi_buffer = NULL; - } - if (tdo_buffer != NULL) { - free(tdo_buffer); - tdo_buffer = NULL; - } - if (tms_buffer != NULL) { - free(tms_buffer); - tms_buffer = NULL; - } + free(tdi_buffer); + tdi_buffer = NULL; + + free(tdo_buffer); + tdo_buffer = NULL; + + free(tms_buffer); + tms_buffer = NULL; } static int vsllink_quit(void) @@ -676,8 +672,7 @@ static int vsllink_jtag_execute(void) return ERROR_JTAG_QUEUE_FAILED; } - if (pending_scan_result->buffer != NULL) - free(pending_scan_result->buffer); + free(pending_scan_result->buffer); } } } else { diff --git a/src/jtag/drivers/xlnx-pcie-xvc.c b/src/jtag/drivers/xlnx-pcie-xvc.c index 1dca5de..2423a9f 100644 --- a/src/jtag/drivers/xlnx-pcie-xvc.c +++ b/src/jtag/drivers/xlnx-pcie-xvc.c @@ -282,8 +282,7 @@ static int xlnx_pcie_xvc_execute_scan(struct jtag_command *cmd) }; err = jtag_read_buffer(buf, cmd->cmd.scan); - if (buf) - free(buf); + free(buf); if (tap_get_state() != tap_get_end_state()) err = xlnx_pcie_xvc_execute_statemove(1); @@ -291,8 +290,7 @@ static int xlnx_pcie_xvc_execute_scan(struct jtag_command *cmd) return err; out_err: - if (buf) - free(buf); + free(buf); return err; } @@ -456,8 +454,7 @@ COMMAND_HANDLER(xlnx_pcie_xvc_handle_config_command) * limit the memory we're leaking by freeing the old one first * before allocating a new one ... */ - if (xlnx_pcie_xvc->device) - free(xlnx_pcie_xvc->device); + free(xlnx_pcie_xvc->device); xlnx_pcie_xvc->device = strdup(CMD_ARGV[0]); return ERROR_OK; diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 1335c29..153a98e 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1155,10 +1155,8 @@ COMMAND_HANDLER(handle_irscan_command) retval = jtag_execute_queue(); error_return: - for (i = 0; i < num_fields; i++) { - if (NULL != fields[i].out_value) - free((void *)fields[i].out_value); - } + for (i = 0; i < num_fields; i++) + free((void *)fields[i].out_value); free(fields); |