From 08ee7bb982b16742f52cfdc6c649d82ffa2eb177 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 3 Jul 2021 18:51:20 +0200 Subject: openocd: fix simple cases of NULL comparison There are more than 1000 NULL comparisons to be aligned to the coding style. For recurrent NULL comparison it's preferable using trivial scripts in order to minimize the review effort. Patch generated automatically with the command: sed -i PATTERN $(find src/ -type f) where PATTERN is in the list: 's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g' Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6350 Tested-by: jenkins --- src/jtag/drivers/arm-jtag-ew.c | 2 +- src/jtag/drivers/bitq.c | 2 +- src/jtag/drivers/buspirate.c | 4 +- src/jtag/drivers/cmsis_dap.c | 10 +-- src/jtag/drivers/cmsis_dap_usb_bulk.c | 6 +- src/jtag/drivers/cmsis_dap_usb_hid.c | 16 ++--- src/jtag/drivers/driver.c | 4 +- src/jtag/drivers/ft232r.c | 6 +- src/jtag/drivers/ftdi.c | 4 +- src/jtag/drivers/jlink.c | 2 +- src/jtag/drivers/jtag_dpi.c | 22 +++--- src/jtag/drivers/jtag_usb_common.c | 4 +- src/jtag/drivers/kitprog.c | 16 ++--- src/jtag/drivers/libusb_helper.c | 2 +- src/jtag/drivers/linuxgpiod.c | 28 ++++---- src/jtag/drivers/mpsse.c | 4 +- src/jtag/drivers/opendous.c | 6 +- src/jtag/drivers/openjtag.c | 6 +- src/jtag/drivers/parport.c | 2 +- src/jtag/drivers/presto.c | 2 +- src/jtag/drivers/remote_bitbang.c | 6 +- src/jtag/drivers/rlink.c | 6 +- src/jtag/drivers/stlink_usb.c | 98 +++++++++++++------------- src/jtag/drivers/ti_icdi_usb.c | 4 +- src/jtag/drivers/ulink.c | 42 +++++------ src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c | 6 +- src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c | 10 +-- src/jtag/drivers/versaloon/versaloon.c | 26 +++---- src/jtag/drivers/vsllink.c | 6 +- src/jtag/drivers/xds110.c | 34 ++++----- 30 files changed, 193 insertions(+), 193 deletions(-) (limited to 'src/jtag/drivers') diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index 62d8631..5b5a966 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -103,7 +103,7 @@ static int armjtagew_execute_queue(void) enum scan_type type; uint8_t *buffer; - while (cmd != NULL) { + while (cmd) { switch (cmd->type) { case JTAG_RUNTEST: LOG_DEBUG_IO("runtest %i cycles, end in %i", diff --git a/src/jtag/drivers/bitq.c b/src/jtag/drivers/bitq.c index 97734a9..04fc78b 100644 --- a/src/jtag/drivers/bitq.c +++ b/src/jtag/drivers/bitq.c @@ -168,7 +168,7 @@ static void bitq_scan_field(struct scan_field *field, int do_pause) else tdo_req = 0; - if (field->out_value == NULL) { + if (!field->out_value) { /* just send zeros and request data from TDO */ for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) bitq_io(0, 0, tdo_req); diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 5981951..642ad12 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -285,7 +285,7 @@ static bool read_and_discard_all_data(const int fd) static int buspirate_init(void) { - if (buspirate_port == NULL) { + if (!buspirate_port) { LOG_ERROR("You need to specify the serial port!"); return ERROR_JTAG_INIT_FAILED; } @@ -466,7 +466,7 @@ COMMAND_HANDLER(buspirate_handle_port_command) if (CMD_ARGC < 1) return ERROR_COMMAND_SYNTAX_ERROR; - if (buspirate_port == NULL) + if (!buspirate_port) buspirate_port = strdup(CMD_ARGV[0]); return ERROR_OK; diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c index e498ea8..68fd470 100644 --- a/src/jtag/drivers/cmsis_dap.c +++ b/src/jtag/drivers/cmsis_dap.c @@ -269,7 +269,7 @@ static int cmsis_dap_open(void) const struct cmsis_dap_backend *backend = NULL; struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap)); - if (dap == NULL) { + if (!dap) { LOG_ERROR("unable to allocate memory"); return ERROR_FAIL; } @@ -290,7 +290,7 @@ static int cmsis_dap_open(void) } } - if (backend == NULL) { + if (!backend) { LOG_ERROR("unable to find a matching CMSIS-DAP device"); free(dap); return ERROR_FAIL; @@ -1533,14 +1533,14 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int (tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) | (s_len == 64 ? 0 : s_len); - if (sequence != NULL) + if (sequence) bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len); else memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8)); queued_seq_buf_end += cmd_len; - if (tdo_buffer != NULL) { + if (tdo_buffer) { struct pending_scan_result *scan = &pending_scan_results[pending_scan_result_count++]; scan->first = queued_seq_tdo_ptr; queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8); @@ -1799,7 +1799,7 @@ static int cmsis_dap_execute_queue(void) { struct jtag_command *cmd = jtag_command_queue; - while (cmd != NULL) { + while (cmd) { cmsis_dap_execute_command(cmd); cmd = cmd->next; } diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index c42bab2..cb3e02f 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -353,7 +353,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p LOG_WARNING("could not claim interface: %s", libusb_strerror(err)); dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data)); - if (dap->bdata == NULL) { + if (!dap->bdata) { LOG_ERROR("unable to allocate memory"); libusb_release_interface(dev_handle, interface_num); libusb_close(dev_handle); @@ -370,7 +370,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p dap->bdata->interface = interface_num; dap->packet_buffer = malloc(dap->packet_buffer_size); - if (dap->packet_buffer == NULL) { + if (!dap->packet_buffer) { LOG_ERROR("unable to allocate memory"); cmsis_dap_usb_close(dap); return ERROR_FAIL; @@ -446,7 +446,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms) static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) { uint8_t *buf = malloc(pkt_sz); - if (buf == NULL) { + if (!buf) { LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); return ERROR_FAIL; } diff --git a/src/jtag/drivers/cmsis_dap_usb_hid.c b/src/jtag/drivers/cmsis_dap_usb_hid.c index 38069f8..ff0ac78 100644 --- a/src/jtag/drivers/cmsis_dap_usb_hid.c +++ b/src/jtag/drivers/cmsis_dap_usb_hid.c @@ -70,11 +70,11 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p */ devs = hid_enumerate(0x0, 0x0); cur_dev = devs; - while (NULL != cur_dev) { + while (cur_dev) { bool found = false; if (0 == vids[0]) { - if (NULL == cur_dev->product_string) { + if (!cur_dev->product_string) { LOG_DEBUG("Cannot read product string of device 0x%x:0x%x", cur_dev->vendor_id, cur_dev->product_id); } else if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) { @@ -97,10 +97,10 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p if (found) { /* check serial number matches if given */ - if (serial == NULL) + if (!serial) break; - if (cur_dev->serial_number != NULL) { + if (cur_dev->serial_number) { size_t len = (strlen(serial) + 1) * sizeof(wchar_t); wchar_t *wserial = malloc(len); mbstowcs(wserial, serial, len); @@ -118,7 +118,7 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p cur_dev = cur_dev->next; } - if (NULL != cur_dev) { + if (cur_dev) { target_vid = cur_dev->vendor_id; target_pid = cur_dev->product_id; } @@ -129,7 +129,7 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p } dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data)); - if (dap->bdata == NULL) { + if (!dap->bdata) { LOG_ERROR("unable to allocate memory"); return ERROR_FAIL; } @@ -137,7 +137,7 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p dev = hid_open_path(cur_dev->path); hid_free_enumeration(devs); - if (dev == NULL) { + if (!dev) { LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid); return ERROR_FAIL; } @@ -217,7 +217,7 @@ static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) { unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE; uint8_t *buf = malloc(packet_buffer_size); - if (buf == NULL) { + if (!buf) { LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); return ERROR_FAIL; } diff --git a/src/jtag/drivers/driver.c b/src/jtag/drivers/driver.c index 4923f96..e73876c 100644 --- a/src/jtag/drivers/driver.c +++ b/src/jtag/drivers/driver.c @@ -235,7 +235,7 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state struct jtag_command *cmd; cmd = cmd_queue_alloc(sizeof(struct jtag_command)); - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->type = JTAG_TMS; @@ -350,7 +350,7 @@ void interface_jtag_add_callback4(jtag_callback_t callback, entry->data2 = data2; entry->data3 = data3; - if (jtag_callback_queue_head == NULL) { + if (!jtag_callback_queue_head) { jtag_callback_queue_head = entry; jtag_callback_queue_tail = entry; } else { diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c index a63480c..3c02925 100644 --- a/src/jtag/drivers/ft232r.c +++ b/src/jtag/drivers/ft232r.c @@ -176,7 +176,7 @@ static void ft232r_increase_buf_size(size_t new_buf_size) if (new_buf_size >= ft232r_buf_size) { new_buf_size += FT232R_BUF_SIZE_EXTRA; new_buf_ptr = realloc(ft232r_output, new_buf_size); - if (new_buf_ptr != NULL) { + if (new_buf_ptr) { ft232r_output = new_buf_ptr; ft232r_buf_size = new_buf_size; } @@ -259,7 +259,7 @@ static int ft232r_init(void) uint16_t apids[] = {ft232r_pid, 0}; if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) { LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n", - ft232r_vid, ft232r_pid, (ft232r_serial_desc == NULL) ? "[any]" : ft232r_serial_desc); + ft232r_vid, ft232r_pid, (!ft232r_serial_desc) ? "[any]" : ft232r_serial_desc); return ERROR_JTAG_INIT_FAILED; } @@ -310,7 +310,7 @@ static int ft232r_init(void) } ft232r_output = malloc(ft232r_buf_size); - if (ft232r_output == NULL) { + if (!ft232r_output) { LOG_ERROR("Unable to allocate memory for the buffer"); return ERROR_JTAG_INIT_FAILED; } diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index a3d6dac..f17cd9f 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -935,7 +935,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command) if (CMD_ARGC > 0) { n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]); - if (n->name == NULL) + if (!n->name) return ERROR_COMMAND_SYNTAX_ERROR; ftdi_jtag_mode = n->value; @@ -1168,7 +1168,7 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32 * pointers into the queue which may be invalid after the realloc. */ queued_retval = ftdi_swd_run_queue(); struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue)); - if (q != NULL) { + if (q) { swd_cmd_queue = q; swd_cmd_queue_alloced *= 2; LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced); diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 7a2be61..63bcda1 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -294,7 +294,7 @@ static int jlink_execute_queue(void) int ret; struct jtag_command *cmd = jtag_command_queue; - while (cmd != NULL) { + while (cmd) { ret = jlink_execute_command(cmd); if (ret != ERROR_OK) diff --git a/src/jtag/drivers/jtag_dpi.c b/src/jtag/drivers/jtag_dpi.c index f5a67dd..ceb6628 100644 --- a/src/jtag/drivers/jtag_dpi.c +++ b/src/jtag/drivers/jtag_dpi.c @@ -49,7 +49,7 @@ static int last_ir_num_bits; static int write_sock(char *buf, size_t len) { - if (buf == NULL) { + if (!buf) { LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -64,7 +64,7 @@ static int write_sock(char *buf, size_t len) static int read_sock(char *buf, size_t len) { - if (buf == NULL) { + if (!buf) { LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -123,7 +123,7 @@ static int jtag_dpi_scan(struct scan_command *cmd) int ret = ERROR_OK; num_bits = jtag_build_buffer(cmd, &data_buf); - if (data_buf == NULL) { + if (!data_buf) { LOG_ERROR("jtag_build_buffer call failed, data_buf == NULL, " "file %s, line %d", __FILE__, __LINE__); return ERROR_FAIL; @@ -133,7 +133,7 @@ static int jtag_dpi_scan(struct scan_command *cmd) if (cmd->ir_scan) { free(last_ir_buf); last_ir_buf = (uint8_t *)malloc(bytes * sizeof(uint8_t)); - if (last_ir_buf == NULL) { + if (!last_ir_buf) { LOG_ERROR("%s: malloc fail, file %s, line %d", __func__, __FILE__, __LINE__); ret = ERROR_FAIL; @@ -181,7 +181,7 @@ static int jtag_dpi_runtest(int cycles) int num_bits = last_ir_num_bits, bytes; int ret = ERROR_OK; - if (data_buf == NULL) { + if (!data_buf) { LOG_ERROR("%s: NULL 'data_buf' argument, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -194,7 +194,7 @@ static int jtag_dpi_runtest(int cycles) bytes = DIV_ROUND_UP(num_bits, 8); read_scan = (uint8_t *)malloc(bytes * sizeof(uint8_t)); - if (read_scan == NULL) { + if (!read_scan) { LOG_ERROR("%s: malloc fail, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -289,9 +289,9 @@ static int jtag_dpi_init(void) serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(server_port); - if (server_address == NULL) { + if (!server_address) { server_address = strdup(SERVER_ADDRESS); - if (server_address == NULL) { + if (!server_address) { LOG_ERROR("%s: strdup fail, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -350,9 +350,9 @@ COMMAND_HANDLER(jtag_dpi_set_address) if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; else if (CMD_ARGC == 0) { - if (server_address == NULL) { + if (!server_address) { server_address = strdup(SERVER_ADDRESS); - if (server_address == NULL) { + if (!server_address) { LOG_ERROR("%s: strdup fail, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; @@ -362,7 +362,7 @@ COMMAND_HANDLER(jtag_dpi_set_address) } else { free(server_address); server_address = strdup(CMD_ARGV[0]); - if (server_address == NULL) { + if (!server_address) { LOG_ERROR("%s: strdup fail, file %s, line %d", __func__, __FILE__, __LINE__); return ERROR_FAIL; diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index fdd7137..94cd7e7 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -46,7 +46,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH); ptr = strtok(loc, "-"); - if (ptr == NULL) { + if (!ptr) { LOG_WARNING("no '-' in usb path\n"); goto done; } @@ -61,7 +61,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, ptr = strtok(NULL, "."); /* no more tokens in path */ - if (ptr == NULL) + if (!ptr) break; /* path mismatch at some step */ diff --git a/src/jtag/drivers/kitprog.c b/src/jtag/drivers/kitprog.c index 00d3f58..327bb57 100644 --- a/src/jtag/drivers/kitprog.c +++ b/src/jtag/drivers/kitprog.c @@ -158,7 +158,7 @@ static int kitprog_init(void) int retval; kitprog_handle = malloc(sizeof(struct kitprog)); - if (kitprog_handle == NULL) { + if (!kitprog_handle) { LOG_ERROR("Failed to allocate memory"); return ERROR_FAIL; } @@ -208,14 +208,14 @@ static int kitprog_init(void) /* Allocate packet buffers and queues */ kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH; kitprog_handle->packet_buffer = malloc(SWD_MAX_BUFFER_LENGTH); - if (kitprog_handle->packet_buffer == NULL) { + if (!kitprog_handle->packet_buffer) { LOG_ERROR("Failed to allocate memory for the packet buffer"); return ERROR_FAIL; } pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5; pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers)); - if (pending_transfers == NULL) { + if (!pending_transfers) { LOG_ERROR("Failed to allocate memory for the SWD transfer queue"); return ERROR_FAIL; } @@ -256,7 +256,7 @@ static int kitprog_get_usb_serial(void) /* Allocate memory for the serial number */ kitprog_handle->serial = calloc(retval + 1, sizeof(char)); - if (kitprog_handle->serial == NULL) { + if (!kitprog_handle->serial) { LOG_ERROR("Failed to allocate memory for the serial number"); return ERROR_FAIL; } @@ -285,7 +285,7 @@ static int kitprog_usb_open(void) /* Convert the ASCII serial number into a (wchar_t *) */ size_t len = strlen(kitprog_handle->serial); wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t)); - if (hid_serial == NULL) { + if (!hid_serial) { LOG_ERROR("Failed to allocate memory for the serial number"); return ERROR_FAIL; } @@ -298,7 +298,7 @@ static int kitprog_usb_open(void) /* Use HID for the KitBridge interface */ kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial); free(hid_serial); - if (kitprog_handle->hid_handle == NULL) { + if (!kitprog_handle->hid_handle) { LOG_ERROR("Failed to open KitBridge (HID) interface"); return ERROR_FAIL; } @@ -314,7 +314,7 @@ static int kitprog_usb_open(void) static void kitprog_usb_close(void) { - if (kitprog_handle->hid_handle != NULL) { + if (kitprog_handle->hid_handle) { hid_close(kitprog_handle->hid_handle); hid_exit(); } @@ -855,7 +855,7 @@ COMMAND_HANDLER(kitprog_handle_serial_command) { if (CMD_ARGC == 1) { kitprog_serial = strdup(CMD_ARGV[0]); - if (kitprog_serial == NULL) { + if (!kitprog_serial) { LOG_ERROR("Failed to allocate memory for the serial number"); return ERROR_FAIL; } diff --git a/src/jtag/drivers/libusb_helper.c b/src/jtag/drivers/libusb_helper.c index e214eb7..33f680c 100644 --- a/src/jtag/drivers/libusb_helper.c +++ b/src/jtag/drivers/libusb_helper.c @@ -138,7 +138,7 @@ static bool jtag_libusb_match_serial(struct libusb_device_handle *device, char *alternate_serial = adapter_get_alternate_serial(device, dev_desc); /* check possible failures */ - if (alternate_serial == NULL) + if (!alternate_serial) return false; /* then compare and free the alternate serial */ diff --git a/src/jtag/drivers/linuxgpiod.c b/src/jtag/drivers/linuxgpiod.c index 99422a1..03afd3d 100644 --- a/src/jtag/drivers/linuxgpiod.c +++ b/src/jtag/drivers/linuxgpiod.c @@ -207,14 +207,14 @@ static int linuxgpiod_reset(int trst, int srst) LOG_DEBUG("linuxgpiod_reset"); /* assume active low */ - if (gpiod_srst != NULL) { + if (gpiod_srst) { retval1 = gpiod_line_set_value(gpiod_srst, srst ? 0 : 1); if (retval1 < 0) LOG_WARNING("set srst value failed"); } /* assume active low */ - if (gpiod_trst != NULL) { + if (gpiod_trst) { retval2 = gpiod_line_set_value(gpiod_trst, trst ? 0 : 1); if (retval2 < 0) LOG_WARNING("set trst value failed"); @@ -284,7 +284,7 @@ static struct gpiod_line *helper_get_input_line(const char *label, unsigned int int retval; line = gpiod_chip_get_line(gpiod_chip, offset); - if (line == NULL) { + if (!line) { LOG_ERROR("Error get line %s", label); return NULL; } @@ -304,7 +304,7 @@ static struct gpiod_line *helper_get_output_line(const char *label, unsigned int int retval; line = gpiod_chip_get_line(gpiod_chip, offset); - if (line == NULL) { + if (!line) { LOG_ERROR("Error get line %s", label); return NULL; } @@ -325,7 +325,7 @@ static int linuxgpiod_init(void) bitbang_interface = &linuxgpiod_bitbang; gpiod_chip = gpiod_chip_open_by_number(gpiochip); - if (gpiod_chip == NULL) { + if (!gpiod_chip) { LOG_ERROR("Cannot open LinuxGPIOD gpiochip %d", gpiochip); return ERROR_JTAG_INIT_FAILED; } @@ -343,24 +343,24 @@ static int linuxgpiod_init(void) } gpiod_tdo = helper_get_input_line("tdo", tdo_gpio); - if (gpiod_tdo == NULL) + if (!gpiod_tdo) goto out_error; gpiod_tdi = helper_get_output_line("tdi", tdi_gpio, 0); - if (gpiod_tdi == NULL) + if (!gpiod_tdi) goto out_error; gpiod_tck = helper_get_output_line("tck", tck_gpio, 0); - if (gpiod_tck == NULL) + if (!gpiod_tck) goto out_error; gpiod_tms = helper_get_output_line("tms", tms_gpio, 1); - if (gpiod_tms == NULL) + if (!gpiod_tms) goto out_error; if (is_gpio_valid(trst_gpio)) { gpiod_trst = helper_get_output_line("trst", trst_gpio, 1); - if (gpiod_trst == NULL) + if (!gpiod_trst) goto out_error; } } @@ -372,23 +372,23 @@ static int linuxgpiod_init(void) } gpiod_swclk = helper_get_output_line("swclk", swclk_gpio, 1); - if (gpiod_swclk == NULL) + if (!gpiod_swclk) goto out_error; gpiod_swdio = helper_get_output_line("swdio", swdio_gpio, 1); - if (gpiod_swdio == NULL) + if (!gpiod_swdio) goto out_error; } if (is_gpio_valid(srst_gpio)) { gpiod_srst = helper_get_output_line("srst", srst_gpio, 1); - if (gpiod_srst == NULL) + if (!gpiod_srst) goto out_error; } if (is_gpio_valid(led_gpio)) { gpiod_led = helper_get_output_line("led", led_gpio, 0); - if (gpiod_led == NULL) + if (!gpiod_led) goto out_error; } diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 9ba1e25..4e64fdb 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -119,7 +119,7 @@ static bool device_location_equal(struct libusb_device *device, const char *loca LOG_DEBUG("device path has %i steps", path_len); ptr = strtok(loc, "-:"); - if (ptr == NULL) { + if (!ptr) { LOG_DEBUG("no ':' in path"); goto done; } @@ -131,7 +131,7 @@ static bool device_location_equal(struct libusb_device *device, const char *loca path_step = 0; while (path_step < 7) { ptr = strtok(NULL, ".,"); - if (ptr == NULL) { + if (!ptr) { LOG_DEBUG("no more tokens in path at step %i", path_step); break; } diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index 82fcbc1..6881959 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -161,7 +161,7 @@ COMMAND_HANDLER(opendous_handle_opendous_type_command) return ERROR_OK; /* only if the cable name wasn't overwritten by cmdline */ - if (opendous_type == NULL) { + if (!opendous_type) { /* REVISIT first verify that it's listed in cables[] ... */ opendous_type = strdup(CMD_ARGV[0]); } @@ -256,7 +256,7 @@ static int opendous_execute_queue(void) enum scan_type type; uint8_t *buffer; - while (cmd != NULL) { + while (cmd) { switch (cmd->type) { case JTAG_RUNTEST: LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, @@ -331,7 +331,7 @@ static int opendous_init(void) cur_opendous_probe = opendous_probes; - if (opendous_type == NULL) { + if (!opendous_type) { opendous_type = strdup("opendous"); LOG_WARNING("No opendous_type specified, using default 'opendous'"); } diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 6940c88..7efb0e5 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -397,7 +397,7 @@ static int openjtag_init_standard(void) uint8_t latency_timer; /* Open by device description */ - if (openjtag_device_desc == NULL) { + if (!openjtag_device_desc) { LOG_WARNING("no openjtag device description specified, " "using default 'Open JTAG Project'"); openjtag_device_desc = "Open JTAG Project"; @@ -475,7 +475,7 @@ static int openjtag_init_cy7c65215(void) return ERROR_OK; err: - if (usbh != NULL) + if (usbh) jtag_libusb_close(usbh); return ERROR_JTAG_INIT_FAILED; } @@ -803,7 +803,7 @@ static int openjtag_execute_queue(void) { struct jtag_command *cmd = jtag_command_queue; - while (cmd != NULL) { + while (cmd) { openjtag_execute_command(cmd); cmd = cmd->next; } diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c index e61b20b..1d7fcc4 100644 --- a/src/jtag/drivers/parport.c +++ b/src/jtag/drivers/parport.c @@ -272,7 +272,7 @@ static int parport_init(void) cur_cable = cables; - if (parport_cable == NULL) { + if (!parport_cable) { parport_cable = strdup("wiggler"); LOG_WARNING("No parport cable specified, using default 'wiggler'"); } diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c index 43d669e..b6f110b 100644 --- a/src/jtag/drivers/presto.c +++ b/src/jtag/drivers/presto.c @@ -534,7 +534,7 @@ static int presto_jtag_init(void) { if (presto_open(presto_serial) != ERROR_OK) { presto_close(); - if (presto_serial != NULL) + if (presto_serial) LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial); else LOG_ERROR("Cannot open PRESTO"); diff --git a/src/jtag/drivers/remote_bitbang.c b/src/jtag/drivers/remote_bitbang.c index 57f0c6e..ac1040e 100644 --- a/src/jtag/drivers/remote_bitbang.c +++ b/src/jtag/drivers/remote_bitbang.c @@ -263,7 +263,7 @@ static int remote_bitbang_init_tcp(void) freeaddrinfo(result); /* No longer needed */ - if (rp == NULL) { /* No address succeeded */ + if (!rp) { /* No address succeeded */ log_socket_error("Failed to connect"); return ERROR_FAIL; } @@ -273,7 +273,7 @@ static int remote_bitbang_init_tcp(void) static int remote_bitbang_init_unix(void) { - if (remote_bitbang_host == NULL) { + if (!remote_bitbang_host) { LOG_ERROR("host/socket not specified"); return ERROR_FAIL; } @@ -306,7 +306,7 @@ static int remote_bitbang_init(void) remote_bitbang_recv_buf_end = 0; LOG_INFO("Initializing remote_bitbang driver"); - if (remote_bitbang_port == NULL) + if (!remote_bitbang_port) remote_bitbang_fd = remote_bitbang_init_unix(); else remote_bitbang_fd = remote_bitbang_init_tcp(); diff --git a/src/jtag/drivers/rlink.c b/src/jtag/drivers/rlink.c index 07e22ff..7a41a69 100644 --- a/src/jtag/drivers/rlink.c +++ b/src/jtag/drivers/rlink.c @@ -608,7 +608,7 @@ static inline struct dtc_reply_queue_entry *dtc_queue_enqueue_reply( struct dtc_reply_queue_entry *rq_entry; rq_entry = malloc(sizeof(struct dtc_reply_queue_entry)); - if (rq_entry != NULL) { + if (rq_entry) { rq_entry->scan.type = type; rq_entry->scan.buffer = buffer; rq_entry->scan.size = size; @@ -617,7 +617,7 @@ static inline struct dtc_reply_queue_entry *dtc_queue_enqueue_reply( rq_entry->cmd = cmd; rq_entry->next = NULL; - if (dtc_queue.rq_head == NULL) + if (!dtc_queue.rq_head) dtc_queue.rq_head = rq_entry; else dtc_queue.rq_tail->next = rq_entry; @@ -665,7 +665,7 @@ static int dtc_queue_run(void) exit(1); } - if (dtc_queue.rq_head != NULL) { + if (dtc_queue.rq_head) { /* process the reply, which empties the reply queue and frees its entries */ dtc_p = reply_buffer; diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 5d7ab6a..811ad53 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -475,7 +475,7 @@ static unsigned int stlink_usb_block(void *handle) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.flags & STLINK_F_HAS_RW8_512BYTES) return STLINKV3_MAX_RW8; @@ -636,7 +636,7 @@ static int stlink_usb_xfer_v1_get_status(void *handle) struct stlink_usb_handle_s *h = handle; int tr, ret; - assert(handle != NULL); + assert(handle); /* read status */ memset(h->cmdbuf, 0, STLINK_SG_SIZE); @@ -670,7 +670,7 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); size_t n_transfers = 0; struct jtag_xfer transfers[2]; @@ -709,7 +709,7 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int struct stlink_usb_handle_s *h = handle; int tr, ret; - assert(handle != NULL); + assert(handle); ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf, cmdsize, STLINK_WRITE_TIMEOUT, &tr); @@ -742,7 +742,7 @@ static int stlink_usb_xfer_v1_get_sense(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 16); @@ -790,7 +790,7 @@ static int stlink_usb_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int int err, cmdsize = STLINK_CMD_SIZE_V2; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.stlink == 1) { cmdsize = STLINK_SG_SIZE; @@ -823,7 +823,7 @@ static int stlink_tcp_send_cmd(void *handle, int send_size, int recv_size, bool { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* send the TCP command */ int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0); @@ -868,7 +868,7 @@ static int stlink_tcp_xfer_noerrcheck(void *handle, const uint8_t *buf, int size int send_size = STLINK_TCP_USB_CMD_SIZE; int recv_size = STLINK_TCP_SS_SIZE; - assert(handle != NULL); + assert(handle); /* prepare the TCP command */ h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD; @@ -937,7 +937,7 @@ static int stlink_usb_error_check(void *handle) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->st_mode == STLINK_MODE_DEBUG_SWIM) { switch (h->databuf[0]) { @@ -1076,7 +1076,7 @@ static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); assert(h->version.flags & STLINK_F_HAS_TRACE); @@ -1141,7 +1141,7 @@ static int stlink_usb_version(void *handle) char *p; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 6); @@ -1355,7 +1355,7 @@ static int stlink_usb_set_swdclk(void *handle, uint16_t clk_divisor) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ)) return ERROR_COMMAND_NOTFOUND; @@ -1379,7 +1379,7 @@ static int stlink_usb_set_jtagclk(void *handle, uint16_t clk_divisor) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ)) return ERROR_COMMAND_NOTFOUND; @@ -1405,7 +1405,7 @@ static int stlink_usb_current_mode(void *handle, uint8_t *mode) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 2); @@ -1427,7 +1427,7 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type) int rx_size = 0; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* on api V2 we are able the read the latest command * status @@ -1475,7 +1475,7 @@ static int stlink_usb_mode_leave(void *handle, enum stlink_mode type) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* command with no reply, use a valid endpoint but zero size */ stlink_usb_init_buffer(handle, h->rx_ep, 0); @@ -1528,7 +1528,7 @@ static int stlink_usb_exit_mode(void *handle) uint8_t mode; enum stlink_mode emode; - assert(handle != NULL); + assert(handle); res = stlink_usb_current_mode(handle, &mode); @@ -1569,7 +1569,7 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init enum stlink_mode emode; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); res = stlink_usb_exit_mode(handle); if (res != ERROR_OK) @@ -1867,7 +1867,7 @@ static int stlink_usb_idcode(void *handle, uint32_t *idcode) int res, offset; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* there is no swim read core id cmd */ if (h->st_mode == STLINK_MODE_DEBUG_SWIM) { @@ -1905,7 +1905,7 @@ static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *v struct stlink_usb_handle_s *h = handle; int res; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 8); @@ -1926,7 +1926,7 @@ static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 2); @@ -1948,7 +1948,7 @@ static int stlink_usb_trace_read(void *handle, uint8_t *buf, size_t *size) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) { int res; @@ -1999,7 +1999,7 @@ static enum target_state stlink_usb_state(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->reconnect_pending) { LOG_INFO("Previous state query failed, trying to reconnect"); @@ -2041,7 +2041,7 @@ static int stlink_usb_assert_srst(void *handle, int srst) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->st_mode == STLINK_MODE_DEBUG_SWIM) return stlink_swim_assert_reset(handle, srst); @@ -2064,7 +2064,7 @@ static void stlink_usb_trace_disable(void *handle) int res = ERROR_OK; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); assert(h->version.flags & STLINK_F_HAS_TRACE); @@ -2086,7 +2086,7 @@ static int stlink_usb_trace_enable(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.flags & STLINK_F_HAS_TRACE) { stlink_usb_init_buffer(handle, h->rx_ep, 10); @@ -2118,7 +2118,7 @@ static int stlink_usb_reset(void *handle) struct stlink_usb_handle_s *h = handle; int retval; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 2); @@ -2147,7 +2147,7 @@ static int stlink_usb_run(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.jtag_api != STLINK_JTAG_API_V1) { res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN); @@ -2169,7 +2169,7 @@ static int stlink_usb_halt(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.jtag_api != STLINK_JTAG_API_V1) { res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN); @@ -2190,7 +2190,7 @@ static int stlink_usb_step(void *handle) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.jtag_api != STLINK_JTAG_API_V1) { /* TODO: this emulates the v1 api, it should really use a similar auto mask isr @@ -2214,7 +2214,7 @@ static int stlink_usb_read_regs(void *handle) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); stlink_usb_init_buffer(handle, h->rx_ep, 88); @@ -2239,7 +2239,7 @@ static int stlink_usb_read_reg(void *handle, unsigned int regsel, uint32_t *val) int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) { res = stlink_usb_write_debug_reg(h, DCB_DCRSR, regsel & 0x7f); @@ -2279,7 +2279,7 @@ static int stlink_usb_write_reg(void *handle, unsigned int regsel, uint32_t val) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) { int res = stlink_usb_write_debug_reg(h, DCB_DCRDR, val); @@ -2308,7 +2308,7 @@ static int stlink_usb_get_rw_status(void *handle) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (h->version.jtag_api == STLINK_JTAG_API_V1) return ERROR_OK; @@ -2333,7 +2333,7 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, uint16_t read_len = len; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* max 8 bit read/write is 64 bytes or 512 bytes for v3 */ if (len > stlink_usb_block(h)) { @@ -2371,7 +2371,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* max 8 bit read/write is 64 bytes or 512 bytes for v3 */ if (len > stlink_usb_block(h)) { @@ -2403,7 +2403,7 @@ static int stlink_usb_read_mem16(void *handle, uint32_t addr, uint16_t len, int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) return ERROR_COMMAND_NOTFOUND; @@ -2440,7 +2440,7 @@ static int stlink_usb_write_mem16(void *handle, uint32_t addr, uint16_t len, int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) return ERROR_COMMAND_NOTFOUND; @@ -2475,7 +2475,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* data must be a multiple of 4 and word aligned */ if (len % 4 || addr % 4) { @@ -2509,7 +2509,7 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, int res; struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); /* data must be a multiple of 4 and word aligned */ if (len % 4 || addr % 4) { @@ -2985,7 +2985,7 @@ static int stlink_tcp_close(void *handle) /** */ static int stlink_close(void *handle) { - if (handle != NULL) { + if (handle) { struct stlink_usb_handle_s *h = handle; stlink_usb_close(handle); @@ -3064,7 +3064,7 @@ static char *stlink_usb_get_alternate_serial(struct libusb_device_handle *device /* else (len == 26) => buggy ST-Link */ char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char)); - if (alternate_serial == NULL) + if (!alternate_serial) return NULL; for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2) @@ -3307,7 +3307,7 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param) char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0}; uint8_t stlink_used; bool stlink_id_matched = false; - bool stlink_serial_matched = (param->serial == NULL); + bool stlink_serial_matched = (!param->serial); for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) { /* get the stlink info */ @@ -3534,8 +3534,8 @@ static int stlink_config_trace(void *handle, bool enabled, return ERROR_OK; } - assert(trace_freq != NULL); - assert(prescaler != NULL); + assert(trace_freq); + assert(prescaler); if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) { LOG_ERROR("The attached ST-LINK version doesn't support this trace mode"); @@ -3585,7 +3585,7 @@ static int stlink_usb_init_access_port(void *handle, unsigned char ap_num) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_AP_INIT)) return ERROR_COMMAND_NOTFOUND; @@ -3604,7 +3604,7 @@ static int stlink_usb_close_access_port(void *handle, unsigned char ap_num) { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_AP_INIT)) return ERROR_COMMAND_NOTFOUND; @@ -3630,7 +3630,7 @@ static int stlink_read_dap_register(void *handle, unsigned short dap_port, struct stlink_usb_handle_s *h = handle; int retval; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_DAP_REG)) return ERROR_COMMAND_NOTFOUND; @@ -3653,7 +3653,7 @@ static int stlink_write_dap_register(void *handle, unsigned short dap_port, { struct stlink_usb_handle_s *h = handle; - assert(handle != NULL); + assert(handle); if (!(h->version.flags & STLINK_F_HAS_DAP_REG)) return ERROR_COMMAND_NOTFOUND; diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c index 00b2f96..d911fda 100644 --- a/src/jtag/drivers/ti_icdi_usb.c +++ b/src/jtag/drivers/ti_icdi_usb.c @@ -122,7 +122,7 @@ static int icdi_send_packet(void *handle, int len) int result, retry = 0; int transferred = 0; - assert(handle != NULL); + assert(handle); /* check we have a large enough buffer for checksum "#00" */ if (len + 3 > h->max_packet) { @@ -253,7 +253,7 @@ static int icdi_get_cmd_result(void *handle) int offset = 0; char ch; - assert(handle != NULL); + assert(handle); do { ch = h->read_buffer[offset++]; diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index fe95e7d..b2fedbe 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -531,14 +531,14 @@ static int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size, payload = calloc(size, sizeof(uint8_t)); - if (payload == NULL) { + if (!payload) { LOG_ERROR("Could not allocate OpenULINK command payload: out of memory"); return ERROR_FAIL; } switch (direction) { case PAYLOAD_DIRECTION_OUT: - if (ulink_cmd->payload_out != NULL) { + if (ulink_cmd->payload_out) { LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command"); free(payload); return ERROR_FAIL; @@ -548,7 +548,7 @@ static int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size, } break; case PAYLOAD_DIRECTION_IN: - if (ulink_cmd->payload_in_start != NULL) { + if (ulink_cmd->payload_in_start) { LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command"); free(payload); return ERROR_FAIL; @@ -584,7 +584,7 @@ static int ulink_get_queue_size(struct ulink *device, struct ulink_cmd *current = device->queue_start; int sum = 0; - while (current != NULL) { + while (current) { switch (direction) { case PAYLOAD_DIRECTION_OUT: sum += current->payload_out_size + 1; /* + 1 byte for Command ID */ @@ -612,7 +612,7 @@ static void ulink_clear_queue(struct ulink *device) struct ulink_cmd *current = device->queue_start; struct ulink_cmd *next = NULL; - while (current != NULL) { + while (current) { /* Save pointer to next element */ next = current->next; @@ -673,7 +673,7 @@ static int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd) ulink_clear_queue(device); } - if (device->queue_start == NULL) { + if (!device->queue_start) { /* Queue was empty */ device->commands_in_queue = 1; @@ -877,7 +877,7 @@ static int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type, int ret, i, scan_size_bytes; uint8_t bits_last_byte; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; /* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID, @@ -975,7 +975,7 @@ static int ulink_append_clock_tms_cmd(struct ulink *device, uint8_t count, struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; if (device->delay_clock_tms < 0) @@ -1011,7 +1011,7 @@ static int ulink_append_clock_tck_cmd(struct ulink *device, uint16_t count) struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; if (device->delay_clock_tck < 0) @@ -1044,7 +1044,7 @@ static int ulink_append_get_signals_cmd(struct ulink *device) struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_GET_SIGNALS; @@ -1084,7 +1084,7 @@ static int ulink_append_set_signals_cmd(struct ulink *device, uint8_t low, struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_SET_SIGNALS; @@ -1116,7 +1116,7 @@ static int ulink_append_sleep_cmd(struct ulink *device, uint32_t us) struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_SLEEP_US; @@ -1153,7 +1153,7 @@ static int ulink_append_configure_tck_cmd(struct ulink *device, int delay_scan_i struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_CONFIGURE_TCK_FREQ; @@ -1214,7 +1214,7 @@ static int ulink_append_led_cmd(struct ulink *device, uint8_t led_state) struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_SET_LEDS; @@ -1244,7 +1244,7 @@ static int ulink_append_test_cmd(struct ulink *device) struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd)); int ret; - if (cmd == NULL) + if (!cmd) return ERROR_FAIL; cmd->id = CMD_TEST; @@ -1491,7 +1491,7 @@ static int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd) if ((type == SCAN_IN) || (type == SCAN_IO)) { tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes); - if (tdo_buffer_start == NULL) + if (!tdo_buffer_start) return ERROR_FAIL; tdo_buffer = tdo_buffer_start; @@ -1569,9 +1569,9 @@ static int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd) bytecount -= 58; /* Update TDI and TDO buffer pointers */ - if (tdi_buffer_start != NULL) + if (tdi_buffer_start) tdi_buffer += 58; - if (tdo_buffer_start != NULL) + if (tdo_buffer_start) tdo_buffer += 58; } else if (bytecount == 58) { /* Full scan, no further scans */ tms_count_end = last_tms_count; @@ -1871,12 +1871,12 @@ static int ulink_post_process_queue(struct ulink *device) current = device->queue_start; - while (current != NULL) { + while (current) { openocd_cmd = current->cmd_origin; /* Check if a corresponding OpenOCD command is stored for this * OpenULINK command */ - if ((current->needs_postprocessing == true) && (openocd_cmd != NULL)) { + if ((current->needs_postprocessing == true) && (openocd_cmd)) { switch (openocd_cmd->type) { case JTAG_SCAN: ret = ulink_post_process_scan(current); @@ -2122,7 +2122,7 @@ static int ulink_init(void) uint8_t input_signals, output_signals; ulink_handle = calloc(1, sizeof(struct ulink)); - if (ulink_handle == NULL) + if (!ulink_handle) return ERROR_FAIL; libusb_init(&ulink_handle->libusb_ctx); diff --git a/src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c b/src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c index cb4862f..23a5097 100644 --- a/src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c +++ b/src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c @@ -32,7 +32,7 @@ static RESULT usbtoswd_read_callback(void *p, uint8_t *src, uint8_t *processed) { struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p; - if (pending->extra_data != NULL) + if (pending->extra_data) *((uint8_t *)pending->extra_data) = src[0]; return ERROR_OK; @@ -42,7 +42,7 @@ static RESULT usbtoswd_write_callback(void *p, uint8_t *src, uint8_t *processed) { struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p; - if (pending->extra_data != NULL) + if (pending->extra_data) *((uint8_t *)pending->extra_data) = src[0]; /* mark it processed to ignore other input data */ @@ -135,7 +135,7 @@ RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request, parity += (request >> 4) & 1; parity &= 1; buff[0] = (request | 0x81 | (parity << 5)) & ~0x40; - if (data != NULL) + if (data) SET_LE_U32(&buff[1], *data); else memset(buff + 1, 0, 4); diff --git a/src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c b/src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c index b46bbe0..ee3b724 100644 --- a/src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c +++ b/src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c @@ -90,7 +90,7 @@ static RESULT usbtoxxx_validate_current_command_type(void) { if (type_pre > 0) { /* not the first command */ - if (NULL == usbtoxxx_buffer) { + if (!usbtoxxx_buffer) { LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer)); return ERRCODE_INVALID_BUFFER; } @@ -182,8 +182,8 @@ RESULT usbtoxxx_execute_command(void) struct versaloon_want_pos_t *tmp; tmp = versaloon_pending[i].pos; - while (tmp != NULL) { - if ((tmp->buff != NULL) && (tmp->size > 0)) { + while (tmp) { + if ((tmp->buff) && (tmp->size > 0)) { memcpy(tmp->buff, versaloon_buf + usbtoxxx_buffer_index + tmp->offset, @@ -332,7 +332,7 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf, if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6)) return ERROR_FAIL; - if ((type_pre != type) || (NULL == usbtoxxx_buffer)) { + if ((type_pre != type) || (!usbtoxxx_buffer)) { if (ERROR_OK != usbtoxxx_validate_current_command_type()) { LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); return ERRCODE_FAILURE_OPERATION; @@ -357,7 +357,7 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf, SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp); } - if (cmdbuf != NULL) { + if (cmdbuf) { memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen); usbtoxxx_current_cmd_index += cmdlen; } diff --git a/src/jtag/drivers/versaloon/versaloon.c b/src/jtag/drivers/versaloon/versaloon.c index c6e390c..199c898 100644 --- a/src/jtag/drivers/versaloon/versaloon.c +++ b/src/jtag/drivers/versaloon/versaloon.c @@ -117,7 +117,7 @@ void versaloon_free_want_pos(void) struct versaloon_want_pos_t *tmp, *free_tmp; tmp = versaloon_want_pos; - while (tmp != NULL) { + while (tmp) { free_tmp = tmp; tmp = tmp->next; free(free_tmp); @@ -126,7 +126,7 @@ void versaloon_free_want_pos(void) for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) { tmp = versaloon_pending[i].pos; - while (tmp != NULL) { + while (tmp) { free_tmp = tmp; tmp = tmp->next; free(free_tmp); @@ -140,7 +140,7 @@ RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff) struct versaloon_want_pos_t *new_pos = NULL; new_pos = malloc(sizeof(*new_pos)); - if (NULL == new_pos) { + if (!new_pos) { LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); return ERRCODE_NOT_ENOUGH_MEMORY; } @@ -149,12 +149,12 @@ RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff) new_pos->buff = buff; new_pos->next = NULL; - if (NULL == versaloon_want_pos) + if (!versaloon_want_pos) versaloon_want_pos = new_pos; else { struct versaloon_want_pos_t *tmp = versaloon_want_pos; - while (tmp->next != NULL) + while (tmp->next) tmp = tmp->next; tmp->next = new_pos; } @@ -199,7 +199,7 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen) int transferred; #if PARAM_CHECK - if (NULL == versaloon_buf) { + if (!versaloon_buf) { LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); return ERRCODE_INVALID_BUFFER; } @@ -217,7 +217,7 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen) return ERRCODE_FAILURE_OPERATION; } - if (inlen != NULL) { + if (inlen) { ret = libusb_bulk_transfer(versaloon_usb_device_handle, versaloon_interface.usb_setting.ep_in, versaloon_buf, versaloon_interface.usb_setting.buf_size, @@ -242,7 +242,7 @@ static RESULT versaloon_init(void) /* malloc temporary buffer */ versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size); - if (NULL == versaloon_buf) { + if (!versaloon_buf) { LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); return ERRCODE_NOT_ENOUGH_MEMORY; } @@ -274,13 +274,13 @@ static RESULT versaloon_init(void) versaloon_buf = NULL; versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size); - if (NULL == versaloon_buf) { + if (!versaloon_buf) { versaloon_fini(); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); return ERRCODE_NOT_ENOUGH_MEMORY; } versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3); - if (NULL == versaloon_cmd_buf) { + if (!versaloon_cmd_buf) { versaloon_fini(); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); return ERRCODE_NOT_ENOUGH_MEMORY; @@ -294,7 +294,7 @@ static RESULT versaloon_init(void) static RESULT versaloon_fini(void) { - if (versaloon_usb_device_handle != NULL) { + if (versaloon_usb_device_handle) { usbtoxxx_fini(); versaloon_free_want_pos(); @@ -325,11 +325,11 @@ static RESULT versaloon_get_target_voltage(uint16_t *voltage) uint16_t inlen; #if PARAM_CHECK - if (NULL == versaloon_buf) { + if (!versaloon_buf) { LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); return ERRCODE_INVALID_BUFFER; } - if (NULL == voltage) { + if (!voltage) { LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__); return ERRCODE_INVALID_PARAMETER; } diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 6a592bc..b4597b7 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -105,7 +105,7 @@ static int vsllink_execute_queue(void) " vsllink " "-------------------------------------"); - while (cmd != NULL) { + while (cmd) { switch (cmd->type) { case JTAG_RUNTEST: LOG_DEBUG_IO("runtest %i cycles, end in %s", @@ -280,7 +280,7 @@ static int vsllink_quit(void) static int vsllink_interface_init(void) { vsllink_handle = malloc(sizeof(struct vsllink)); - if (NULL == vsllink_handle) { + if (!vsllink_handle) { LOG_ERROR("unable to allocate memory"); return ERROR_FAIL; } @@ -333,7 +333,7 @@ static int vsllink_init(void) tdi_buffer = malloc(tap_buffer_size); tdo_buffer = malloc(tap_buffer_size); tms_buffer = malloc(tap_buffer_size); - if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) { + if ((!tdi_buffer) || (!tdo_buffer) || (!tms_buffer)) { vsllink_quit(); return ERROR_FAIL; } diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index 1a17f70..e89cfe5 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -400,7 +400,7 @@ static bool usb_connect(void) * 2) didn't find the XDS110, and no devices are currently open */ - if (NULL != list) { + if (list) { /* Free the device list, we're done with it */ libusb_free_device_list(list, 1); } @@ -431,12 +431,12 @@ static bool usb_connect(void) /* On an error, clean up what we can */ if (0 != result) { - if (NULL != dev) { + if (dev) { /* Release the debug and data interface on the XDS110 */ (void)libusb_release_interface(dev, xds110.interface); libusb_close(dev); } - if (NULL != ctx) + if (ctx) libusb_exit(ctx); xds110.ctx = NULL; xds110.dev = NULL; @@ -453,13 +453,13 @@ static bool usb_connect(void) static void usb_disconnect(void) { - if (NULL != xds110.dev) { + if (xds110.dev) { /* Release the debug and data interface on the XDS110 */ (void)libusb_release_interface(xds110.dev, xds110.interface); libusb_close(xds110.dev); xds110.dev = NULL; } - if (NULL != xds110.ctx) { + if (xds110.ctx) { libusb_exit(xds110.ctx); xds110.ctx = NULL; } @@ -505,7 +505,7 @@ static bool usb_write(unsigned char *buffer, int size, int *written) retries++; } - if (NULL != written) + if (written) *written = bytes_written; return (result == 0 && size == bytes_written) ? true : false; @@ -550,7 +550,7 @@ static bool usb_get_response(uint32_t *total_bytes_read, uint32_t timeout) /* Abort now if we didn't receive a valid response */ if (!success) { - if (NULL != total_bytes_read) + if (total_bytes_read) *total_bytes_read = 0; return false; } @@ -587,7 +587,7 @@ static bool usb_get_response(uint32_t *total_bytes_read, uint32_t timeout) if (!success) count = 0; - if (NULL != total_bytes_read) + if (total_bytes_read) *total_bytes_read = count; return success; @@ -636,7 +636,7 @@ static bool xds_execute(uint32_t out_length, uint32_t in_length, int error = 0; uint32_t bytes_read = 0; - if (NULL == xds110.dev) + if (!xds110.dev) return false; while (!done && attempts > 0) { @@ -714,9 +714,9 @@ static bool xds_version(uint32_t *firmware_id, uint16_t *hardware_id) DEFAULT_TIMEOUT); if (success) { - if (NULL != firmware_id) + if (firmware_id) *firmware_id = xds110_get_u32(fw_id_pntr); - if (NULL != hardware_id) + if (hardware_id) *hardware_id = xds110_get_u16(hw_id_pntr); } @@ -863,7 +863,7 @@ static bool cmapi_connect(uint32_t *idcode) DEFAULT_TIMEOUT); if (success) { - if (NULL != idcode) + if (idcode) *idcode = xds110_get_u32(idcode_pntr); } @@ -926,7 +926,7 @@ static bool cmapi_read_dap_reg(uint32_t type, uint32_t ap_num, DEFAULT_TIMEOUT); if (success) { - if (NULL != value) + if (value) *value = xds110_get_u32(value_pntr); } @@ -943,7 +943,7 @@ static bool cmapi_write_dap_reg(uint32_t type, uint32_t ap_num, bool success; - if (NULL == value) + if (!value) return false; xds110.write_payload[0] = CMAPI_REG_WRITE; @@ -1086,7 +1086,7 @@ static bool ocd_pathmove(uint32_t num_states, uint8_t *path) bool success; - if (NULL == path) + if (!path) return false; xds110.write_payload[0] = OCD_PATHMOVE; @@ -1209,7 +1209,7 @@ static bool xds110_legacy_read_reg(uint8_t cmd, uint32_t *value) /* Handle result of read attempt */ if (!success) LOG_ERROR("XDS110: failed to read DAP register"); - else if (NULL != value) + else if (value) *value = reg_value; if (success && DAP_AP == type) { @@ -1867,7 +1867,7 @@ static int xds110_execute_queue(void) { struct jtag_command *cmd = jtag_command_queue; - while (cmd != NULL) { + while (cmd) { xds110_execute_command(cmd); cmd = cmd->next; } -- cgit v1.1