diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c index 5a200eb77..7144632df 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 81721cbb4..e9ff8dfa1 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 60b119548..40d52acb9 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 b33e87f2a..df1d601b8 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 2483b4346..dc38c5db0 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 3c54809c0..d97db56a6 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 d2b97b96e..4fa83ae56 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 "); @@ -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 cad2e1b99..ef4b5d929 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 6337272fb..969ea8406 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 789d3a466..32a43f8bf 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 4f38d195d..5538bcd73 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 7488d9dd8..fe8b6b82c 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 bccd3ddb0..f0e4f566d 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 7eab5c130..2cf5751d6 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 b3abd1205..b203c828b 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 4046b22dd..6c3a187db 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 f316c8256..d276e588f 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 3c9c3a769..9648ba2e2 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 dd7dcdb4b..627e4653d 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 35a0deff5..8efe44353 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 6f2296e6d..9aaed36b7 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 1dca5def8..2423a9f05 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 1335c2917..153a98e1b 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);