Don't compare pointers with 0, use NULL when needed.
Don't assign pointer to 0, use NULL.
Don't pass 0 ad pointer argument, pass NULL.
While there, check for return value from malloc(), replace an
assert() with a LOG_ERROR(), drop a useless cast.
Detected through 'sparse' tool.
Change-Id: Ia7cf52221b12198aba1a07ebdfaf57ce341d5699
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7592
Tested-by: jenkins
armjtagew_handle = armjtagew_usb_open();
- if (armjtagew_handle == 0) {
+ if (!armjtagew_handle) {
LOG_ERROR(
"Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED;
static struct bitbang_interface at91rm9200_bitbang = {
.read = at91rm9200_read,
.write = at91rm9200_write,
- .blink = 0
+ .blink = NULL,
};
static bb_value_t at91rm9200_read(void)
return ERROR_COMMAND_SYNTAX_ERROR;
/* only if the device name wasn't overwritten by cmdline */
- if (at91rm9200_device == 0) {
+ if (!at91rm9200_device) {
at91rm9200_device = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
+ if (!at91rm9200_device) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
strcpy(at91rm9200_device, CMD_ARGV[0]);
}
static struct bitbang_interface ep93xx_bitbang = {
.read = ep93xx_read,
.write = ep93xx_write,
- .blink = 0,
+ .blink = NULL,
};
static bb_value_t ep93xx_read(void)
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
- SIO_SET_BAUD_RATE, divisor, 0, 0, 0, 1000) != 0) {
+ SIO_SET_BAUD_RATE, divisor, 0, NULL, 0, 1000) != 0) {
LOG_ERROR("cannot set baud rate");
return ERROR_JTAG_DEVICE_ERROR;
}
/* Reset the device. */
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
- SIO_RESET, 0, 0, 0, 0, 1000) != 0) {
+ SIO_RESET, 0, 0, NULL, 0, 1000) != 0) {
LOG_ERROR("unable to reset device");
return ERROR_JTAG_INIT_FAILED;
}
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
SIO_SET_BITMODE, (1<<tck_gpio) | (1<<tdi_gpio) | (1<<tms_gpio) | (1<<ntrst_gpio) | (1<<nsysrst_gpio) | 0x400,
- 0, 0, 0, 1000) != 0) {
+ 0, NULL, 0, 1000) != 0) {
LOG_ERROR("cannot set sync bitbang mode");
return ERROR_JTAG_INIT_FAILED;
}
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
SIO_SET_BAUD_RATE, divisor,
- 0, 0, 0, 1000) != 0) {
+ 0, NULL, 0, 1000) != 0) {
LOG_ERROR("cannot set baud rate");
return ERROR_JTAG_INIT_FAILED;
}
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
- SIO_SET_LATENCY_TIMER, latency_timer, 0, 0, 0, 1000) != 0) {
+ SIO_SET_LATENCY_TIMER, latency_timer, 0, NULL, 0, 1000) != 0) {
LOG_ERROR("unable to set latency timer");
return ERROR_JTAG_INIT_FAILED;
}
if (jtag_libusb_control_transfer(adapter,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
SIO_SET_BITMODE, ft232r_restore_bitmode,
- 0, 0, 0, 1000) != 0) {
+ 0, NULL, 0, 1000) != 0) {
LOG_ERROR("cannot set bitmode to restore serial port");
}
}
oe = s->invert_oe;
break;
default:
- assert(0 && "invalid signal level specifier");
+ LOG_ERROR("invalid signal level specifier \'%c\'(0x%02x)", value, value);
return ERROR_FAIL;
}
int err;
if (!ctx)
- return 0;
+ return NULL;
bit_copy_queue_init(&ctx->read_queue);
ctx->read_chunk_size = 16384;
description ? description : "*",
serial ? serial : "*",
location ? location : "*");
- ctx->usb_dev = 0;
+ ctx->usb_dev = NULL;
goto error;
}
return ctx;
error:
mpsse_close(ctx);
- return 0;
+ return NULL;
}
void mpsse_close(struct mpsse_ctx *ctx)
void mpsse_clock_data_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset,
unsigned length, uint8_t mode)
{
- mpsse_clock_data(ctx, out, out_offset, 0, 0, length, mode);
+ mpsse_clock_data(ctx, out, out_offset, NULL, 0, length, mode);
}
void mpsse_clock_data_in(struct mpsse_ctx *ctx, uint8_t *in, unsigned in_offset, unsigned length,
uint8_t mode)
{
- mpsse_clock_data(ctx, 0, 0, in, in_offset, length, mode);
+ mpsse_clock_data(ctx, NULL, 0, in, in_offset, length, mode);
}
void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in,
void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset,
unsigned length, bool tdi, uint8_t mode)
{
- mpsse_clock_tms_cs(ctx, out, out_offset, 0, 0, length, tdi, mode);
+ mpsse_clock_tms_cs(ctx, out, out_offset, NULL, 0, length, tdi, mode);
}
void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in,
if (ctx->write_count == 0)
return retval;
- struct libusb_transfer *read_transfer = 0;
+ struct libusb_transfer *read_transfer = NULL;
struct transfer_result read_result = { .ctx = ctx, .done = true };
if (ctx->read_count) {
buffer_write_byte(ctx, 0x87); /* SEND_IMMEDIATE */
opendous_jtag_handle = opendous_usb_open();
- if (opendous_jtag_handle == 0) {
+ if (!opendous_jtag_handle) {
LOG_ERROR("Cannot find opendous Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED;
}
return ERROR_OK;
/* only if the cable name wasn't overwritten by cmdline */
- if (parport_cable == 0) {
+ if (!parport_cable) {
/* REVISIT first verify that it's listed in cables[] ... */
parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
+ if (!parport_cable) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
strcpy(parport_cable, CMD_ARGV[0]);
}
uint8_t dtc_mask, tdo_mask;
uint8_t reply_buffer[USB_EP2IN_SIZE];
- assert((dtc_queue.rq_head != 0) == (dtc_queue.reply_index > 0));
+ assert((!!dtc_queue.rq_head) == (dtc_queue.reply_index > 0));
assert(dtc_queue.cmd_index < USB_EP2BANK_SIZE);
assert(dtc_queue.reply_index <= USB_EP2IN_SIZE);
h = calloc(1, sizeof(struct stlink_usb_handle_s));
- if (h == 0) {
+ if (!h) {
LOG_DEBUG("malloc failed");
return ERROR_FAIL;
}
.swdio_read = sysfsgpio_swdio_read,
.swdio_drive = sysfsgpio_swdio_drive,
.swd_write = sysfsgpio_swd_write,
- .blink = 0
+ .blink = NULL,
};
/* helper func to close and cleanup files only if they were valid/ used */
if (h->max_packet != ICDI_PACKET_SIZE) {
h->read_buffer = realloc(h->read_buffer, h->max_packet);
h->write_buffer = realloc(h->write_buffer, h->max_packet);
- if (h->read_buffer == 0 || h->write_buffer == 0) {
+ if (!h->read_buffer || !h->write_buffer) {
LOG_ERROR("unable to reallocate memory");
return ERROR_FAIL;
}
h = calloc(1, sizeof(struct icdi_usb_handle_s));
- if (h == 0) {
+ if (!h) {
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
h->write_buffer = malloc(ICDI_PACKET_SIZE);
h->max_packet = ICDI_PACKET_SIZE;
- if (h->read_buffer == 0 || h->write_buffer == 0) {
+ if (!h->read_buffer || !h->write_buffer) {
LOG_DEBUG("malloc failed");
goto error_open;
}
usbprog_jtag_handle = usbprog_jtag_open();
tms_chain_index = 0;
- if (usbprog_jtag_handle == 0) {
+ if (!usbprog_jtag_handle) {
LOG_ERROR("Can't find USB JTAG Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED;
}
/* Transfer results into caller's buffers */
for (result = 0; result < xds110.txn_result_count; result++)
- if (xds110.txn_dap_results[result] != 0)
+ if (xds110.txn_dap_results[result])
*xds110.txn_dap_results[result] = dap_results[result];
xds110.txn_request_size = 0;
}
bits = 0;
}
- if (xds110.txn_scan_results[result].buffer != 0)
+ if (xds110.txn_scan_results[result].buffer)
bit_copy(xds110.txn_scan_results[result].buffer, 0, data_pntr,
bits, xds110.txn_scan_results[result].num_bits);
bits += xds110.txn_scan_results[result].num_bits;
if (num_states == 0)
return;
- path = (uint8_t *)malloc(num_states * sizeof(uint8_t));
- if (path == 0) {
+ path = malloc(num_states * sizeof(uint8_t));
+ if (path) {
LOG_ERROR("XDS110: unable to allocate memory");
return;
}
/* Clear data out buffer to default value of all zeros */
memset((void *)buffer, 0x00, total_bytes);
for (i = 0; i < cmd->cmd.scan->num_fields; i++) {
- if (cmd->cmd.scan->fields[i].out_value != 0) {
+ if (cmd->cmd.scan->fields[i].out_value) {
/* Copy over data to scan out into request buffer */
bit_copy(buffer, offset, cmd->cmd.scan->fields[i].out_value, 0,
cmd->cmd.scan->fields[i].num_bits);