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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6350
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2021-07-03 18:51:20 +02:00
parent b159f5cded
commit 08ee7bb982
166 changed files with 856 additions and 856 deletions

View File

@ -25,7 +25,7 @@
unsigned get_flash_name_index(const char *name) unsigned get_flash_name_index(const char *name)
{ {
const char *name_index = strrchr(name, '.'); const char *name_index = strrchr(name, '.');
if (NULL == name_index) if (!name_index)
return 0; return 0;
if (name_index[1] < '0' || name_index[1] > '9') if (name_index[1] < '0' || name_index[1] > '9')
return ~0U; return ~0U;

View File

@ -731,7 +731,7 @@ NAND_DEVICE_COMMAND_HANDLER(davinci_nand_device_command)
} }
info = calloc(1, sizeof(*info)); info = calloc(1, sizeof(*info));
if (info == NULL) if (!info)
goto fail; goto fail;
info->eccmode = eccmode; info->eccmode = eccmode;

View File

@ -65,7 +65,7 @@ int nand_fileio_start(struct command_invocation *cmd,
duration_start(&state->bench); duration_start(&state->bench);
if (NULL != filename) { if (filename) {
int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY); int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
const char *msg = (filemode == FILEIO_READ) ? "read" : "write"; const char *msg = (filemode == FILEIO_READ) ? "read" : "write";
@ -127,7 +127,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state,
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (NULL == nand->device) { if (!nand->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]); command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_NAND_DEVICE_NOT_PROBED; return ERROR_NAND_DEVICE_NOT_PROBED;
} }
@ -184,7 +184,7 @@ int nand_fileio_read(struct nand_device *nand, struct nand_fileio_state *s)
size_t total_read = 0; size_t total_read = 0;
size_t one_read; size_t one_read;
if (NULL != s->page) { if (s->page) {
fileio_read(s->fileio, s->page_size, s->page, &one_read); fileio_read(s->fileio, s->page_size, s->page, &one_read);
if (one_read < s->page_size) if (one_read < s->page_size)
memset(s->page + one_read, 0xff, s->page_size - one_read); memset(s->page + one_read, 0xff, s->page_size - one_read);
@ -213,7 +213,7 @@ int nand_fileio_read(struct nand_device *nand, struct nand_fileio_state *s)
nand_calculate_ecc_kw(nand, s->page + i, ecc); nand_calculate_ecc_kw(nand, s->page + i, ecc);
ecc += 10; ecc += 10;
} }
} else if (NULL != s->oob) { } else if (s->oob) {
fileio_read(s->fileio, s->oob_size, s->oob, &one_read); fileio_read(s->fileio, s->oob_size, s->oob, &one_read);
if (one_read < s->oob_size) if (one_read < s->oob_size)
memset(s->oob + one_read, 0xff, s->oob_size - one_read); memset(s->oob + one_read, 0xff, s->oob_size - one_read);

View File

@ -64,7 +64,7 @@ NAND_DEVICE_COMMAND_HANDLER(imx31_nand_device_command)
{ {
struct mx3_nf_controller *mx3_nf_info; struct mx3_nf_controller *mx3_nf_info;
mx3_nf_info = malloc(sizeof(struct mx3_nf_controller)); mx3_nf_info = malloc(sizeof(struct mx3_nf_controller));
if (mx3_nf_info == NULL) { if (!mx3_nf_info) {
LOG_ERROR("no memory for nand controller"); LOG_ERROR("no memory for nand controller");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -89,7 +89,7 @@ NAND_DEVICE_COMMAND_HANDLER(mxc_nand_device_command)
int hwecc_needed; int hwecc_needed;
mxc_nf_info = malloc(sizeof(struct mxc_nf_controller)); mxc_nf_info = malloc(sizeof(struct mxc_nf_controller));
if (mxc_nf_info == NULL) { if (!mxc_nf_info) {
LOG_ERROR("no memory for nand controller"); LOG_ERROR("no memory for nand controller");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -34,7 +34,7 @@ S3C24XX_DEVICE_COMMAND()
struct s3c24xx_nand_controller *s3c24xx_info; struct s3c24xx_nand_controller *s3c24xx_info;
s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller)); s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
if (s3c24xx_info == NULL) { if (!s3c24xx_info) {
LOG_ERROR("no memory for nand controller"); LOG_ERROR("no memory for nand controller");
return -ENOMEM; return -ENOMEM;
} }

View File

@ -86,7 +86,7 @@ COMMAND_HANDLER(handle_nand_info_command)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (NULL == p->device) { if (!p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]); command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK; return ERROR_OK;
} }
@ -359,10 +359,10 @@ COMMAND_HANDLER(handle_nand_dump_command)
return retval; return retval;
} }
if (NULL != s.page) if (s.page)
fileio_write(s.fileio, s.page_size, s.page, &size_written); fileio_write(s.fileio, s.page_size, s.page, &size_written);
if (NULL != s.oob) if (s.oob)
fileio_write(s.fileio, s.oob_size, s.oob, &size_written); fileio_write(s.fileio, s.oob_size, s.oob, &size_written);
s.size -= nand->page_size; s.size -= nand->page_size;
@ -391,7 +391,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (NULL == p->device) { if (!p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]); command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK; return ERROR_OK;
} }
@ -527,14 +527,14 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name,
return ERROR_COMMAND_ARGUMENT_INVALID; return ERROR_COMMAND_ARGUMENT_INVALID;
} }
if (NULL != controller->commands) { if (controller->commands) {
retval = register_commands(CMD_CTX, NULL, retval = register_commands(CMD_CTX, NULL,
controller->commands); controller->commands);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
} }
c = malloc(sizeof(struct nand_device)); c = malloc(sizeof(struct nand_device));
if (c == NULL) { if (!c) {
LOG_ERROR("End of memory"); LOG_ERROR("End of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -560,7 +560,7 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name,
return retval; return retval;
} }
if (controller->usage == NULL) if (!controller->usage)
LOG_DEBUG("'%s' driver usage field missing", controller->name); LOG_DEBUG("'%s' driver usage field missing", controller->name);
nand_device_add(c); nand_device_add(c);
@ -580,7 +580,7 @@ COMMAND_HANDLER(handle_nand_device_command)
const char *driver_name = CMD_ARGV[0]; const char *driver_name = CMD_ARGV[0];
struct nand_flash_controller *controller; struct nand_flash_controller *controller;
controller = nand_driver_find_by_name(CMD_ARGV[0]); controller = nand_driver_find_by_name(CMD_ARGV[0]);
if (NULL == controller) { if (!controller) {
LOG_ERROR("No valid NAND flash driver found (%s)", driver_name); LOG_ERROR("No valid NAND flash driver found (%s)", driver_name);
return CALL_COMMAND_HANDLER(handle_nand_list_drivers); return CALL_COMMAND_HANDLER(handle_nand_list_drivers);
} }

View File

@ -2810,7 +2810,7 @@ static struct sam3_chip *target2sam3(struct target *target)
{ {
struct sam3_chip *chip; struct sam3_chip *chip;
if (target == NULL) if (!target)
return NULL; return NULL;
chip = all_sam3_chips; chip = all_sam3_chips;
@ -3126,7 +3126,7 @@ static int sam3_get_details(struct sam3_bank_private *private)
else else
details++; details++;
} }
if (details->name == NULL) { if (!details->name) {
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)", LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR)); (unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */ /* Help the victim, print details about the chip */
@ -3207,9 +3207,9 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
} }
} }
if (bank->sectors == NULL) { if (!bank->sectors) {
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0]))); bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("No memory!"); LOG_ERROR("No memory!");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -2318,7 +2318,7 @@ static struct sam4_chip *target2sam4(struct target *target)
{ {
struct sam4_chip *chip; struct sam4_chip *chip;
if (target == NULL) if (!target)
return NULL; return NULL;
chip = all_sam4_chips; chip = all_sam4_chips;
@ -2611,7 +2611,7 @@ static int sam4_get_details(struct sam4_bank_private *private)
else else
details++; details++;
} }
if (details->name == NULL) { if (!details->name) {
LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)", LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR)); (unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */ /* Help the victim, print details about the chip */
@ -2662,7 +2662,7 @@ static int sam4_info(struct flash_bank *bank, struct command_invocation *cmd)
int k = bank->size / 1024; int k = bank->size / 1024;
private = get_sam4_bank_private(bank); private = get_sam4_bank_private(bank);
if (private == NULL) if (!private)
return ERROR_FAIL; return ERROR_FAIL;
command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT, command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT,
@ -2715,9 +2715,9 @@ static int sam4_probe(struct flash_bank *bank)
} }
} }
if (bank->sectors == NULL) { if (!bank->sectors) {
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0]))); bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("No memory!"); LOG_ERROR("No memory!");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -385,7 +385,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
{ {
uint8_t devsel = SAMD_GET_DEVSEL(id); uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id); const struct samd_family *family = samd_find_family(id);
if (family == NULL) if (!family)
return NULL; return NULL;
for (unsigned i = 0; i < family->num_parts; i++) { for (unsigned i = 0; i < family->num_parts; i++) {
@ -452,7 +452,7 @@ static int samd_probe(struct flash_bank *bank)
} }
part = samd_find_part(id); part = samd_find_part(id);
if (part == NULL) { if (!part) {
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id); LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -606,7 +606,7 @@ static int samd_get_reservedmask(struct target *target, uint64_t *mask)
} }
const struct samd_family *family; const struct samd_family *family;
family = samd_find_family(id); family = samd_find_family(id);
if (family == NULL) { if (!family) {
LOG_ERROR("Couldn't determine device family"); LOG_ERROR("Couldn't determine device family");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -220,7 +220,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
{ {
uint8_t devsel = SAMD_GET_DEVSEL(id); uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id); const struct samd_family *family = samd_find_family(id);
if (family == NULL) if (!family)
return NULL; return NULL;
for (unsigned i = 0; i < family->num_parts; i++) { for (unsigned i = 0; i < family->num_parts; i++) {
@ -287,7 +287,7 @@ static int same5_probe(struct flash_bank *bank)
} }
part = samd_find_part(id); part = samd_find_part(id);
if (part == NULL) { if (!part) {
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id); LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -332,7 +332,7 @@ static int avrf_probe(struct flash_bank *bank)
} }
} }
if (avr_info != NULL) { if (avr_info) {
free(bank->sectors); free(bank->sectors);
/* chip found */ /* chip found */
@ -398,7 +398,7 @@ static int avrf_info(struct flash_bank *bank, struct command_invocation *cmd)
} }
} }
if (avr_info != NULL) { if (avr_info) {
/* chip found */ /* chip found */
command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name, command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
EXTRACT_VER(device_id)); EXTRACT_VER(device_id));

View File

@ -94,7 +94,7 @@ FLASH_BANK_COMMAND_HANDLER(bluenrgx_flash_bank_command)
bluenrgx_info = calloc(1, sizeof(*bluenrgx_info)); bluenrgx_info = calloc(1, sizeof(*bluenrgx_info));
/* Check allocation */ /* Check allocation */
if (bluenrgx_info == NULL) { if (!bluenrgx_info) {
LOG_ERROR("failed to allocate bank structure"); LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -140,7 +140,7 @@ static int cc26xx_init(struct flash_bank *bank)
return retval; return retval;
/* Check for working area to use for flash helper algorithm */ /* Check for working area to use for flash helper algorithm */
if (NULL != cc26xx_bank->working_area) if (cc26xx_bank->working_area)
target_free_working_area(target, cc26xx_bank->working_area); target_free_working_area(target, cc26xx_bank->working_area);
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size, retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
&cc26xx_bank->working_area); &cc26xx_bank->working_area);
@ -248,7 +248,7 @@ FLASH_BANK_COMMAND_HANDLER(cc26xx_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
cc26xx_bank = malloc(sizeof(struct cc26xx_bank)); cc26xx_bank = malloc(sizeof(struct cc26xx_bank));
if (NULL == cc26xx_bank) if (!cc26xx_bank)
return ERROR_FAIL; return ERROR_FAIL;
/* Initialize private flash information */ /* Initialize private flash information */
@ -461,7 +461,7 @@ static int cc26xx_probe(struct flash_bank *bank)
num_sectors = max_sectors; num_sectors = max_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors) if (!bank->sectors)
return ERROR_FAIL; return ERROR_FAIL;
bank->base = CC26XX_FLASH_BASE_ADDR; bank->base = CC26XX_FLASH_BASE_ADDR;

View File

@ -93,7 +93,7 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank)); cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank));
if (NULL == cc3220sf_bank) if (!cc3220sf_bank)
return ERROR_FAIL; return ERROR_FAIL;
/* Initialize private flash information */ /* Initialize private flash information */
@ -441,7 +441,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
free(bank->sectors); free(bank->sectors);
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors) if (!bank->sectors)
return ERROR_FAIL; return ERROR_FAIL;
bank->base = base; bank->base = base;

View File

@ -426,7 +426,7 @@ static int cfi_read_intel_pri_ext(struct flash_bank *bank)
free(cfi_info->pri_ext); free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_intel_pri_ext)); pri_ext = malloc(sizeof(struct cfi_intel_pri_ext));
if (pri_ext == NULL) { if (!pri_ext) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -522,7 +522,7 @@ static int cfi_read_spansion_pri_ext(struct flash_bank *bank)
free(cfi_info->pri_ext); free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) { if (!pri_ext) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -624,7 +624,7 @@ static int cfi_read_atmel_pri_ext(struct flash_bank *bank)
free(cfi_info->pri_ext); free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) { if (!pri_ext) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -811,7 +811,7 @@ int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **
} }
cfi_info = calloc(1, sizeof(struct cfi_flash_bank)); cfi_info = calloc(1, sizeof(struct cfi_flash_bank));
if (cfi_info == NULL) { if (!cfi_info) {
LOG_ERROR("No memory for flash bank info"); LOG_ERROR("No memory for flash bank info");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -1488,7 +1488,7 @@ static int cfi_spansion_write_block_mips(struct flash_bank *bank, const uint8_t
/* convert bus-width dependent algorithm code to correct endianness */ /* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size); target_code = malloc(target_code_size);
if (target_code == NULL) { if (!target_code) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -1867,7 +1867,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
/* convert bus-width dependent algorithm code to correct endianness */ /* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size); target_code = malloc(target_code_size);
if (target_code == NULL) { if (!target_code) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -179,7 +179,7 @@ void flash_bank_add(struct flash_bank *bank)
if (flash_banks) { if (flash_banks) {
/* find last flash bank */ /* find last flash bank */
struct flash_bank *p = flash_banks; struct flash_bank *p = flash_banks;
while (NULL != p->next) { while (p->next) {
bank_num += 1; bank_num += 1;
p = p->next; p = p->next;
} }
@ -275,7 +275,7 @@ int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
int retval; int retval;
bank = get_flash_bank_by_name_noprobe(name); bank = get_flash_bank_by_name_noprobe(name);
if (bank != NULL) { if (bank) {
retval = bank->driver->auto_probe(bank); retval = bank->driver->auto_probe(bank);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
@ -293,7 +293,7 @@ int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank)
struct flash_bank *p = get_flash_bank_by_num_noprobe(num); struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
int retval; int retval;
if (p == NULL) if (!p)
return ERROR_FAIL; return ERROR_FAIL;
retval = p->driver->auto_probe(p); retval = p->driver->auto_probe(p);
@ -400,7 +400,7 @@ int default_flash_blank_check(struct flash_bank *bank)
struct target_memory_check_block *block_array; struct target_memory_check_block *block_array;
block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block)); block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block));
if (block_array == NULL) if (!block_array)
return default_flash_mem_blank_check(bank); return default_flash_mem_blank_check(bank);
for (unsigned int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
@ -791,7 +791,7 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
retval = get_flash_bank_by_addr(target, run_address, false, &c); retval = get_flash_bank_by_addr(target, run_address, false, &c);
if (retval != ERROR_OK) if (retval != ERROR_OK)
goto done; goto done;
if (c == NULL) { if (!c) {
LOG_WARNING("no flash bank found for address " TARGET_ADDR_FMT, run_address); LOG_WARNING("no flash bank found for address " TARGET_ADDR_FMT, run_address);
section++; /* and skip it */ section++; /* and skip it */
section_offset = 0; section_offset = 0;
@ -903,7 +903,7 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
/* allocate buffer */ /* allocate buffer */
buffer = malloc(run_size); buffer = malloc(run_size);
if (buffer == NULL) { if (!buffer) {
LOG_ERROR("Out of memory for flash bank buffer"); LOG_ERROR("Out of memory for flash bank buffer");
retval = ERROR_FAIL; retval = ERROR_FAIL;
goto done; goto done;
@ -989,7 +989,7 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
goto done; goto done;
} }
if (written != NULL) if (written)
*written += run_size; /* add run size to total written counter */ *written += run_size; /* add run size to total written counter */
} }
@ -1010,7 +1010,7 @@ struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
unsigned int num_blocks) unsigned int num_blocks)
{ {
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector)); struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
if (array == NULL) if (!array)
return NULL; return NULL;
for (unsigned int i = 0; i < num_blocks; i++) { for (unsigned int i = 0; i < num_blocks; i++) {

View File

@ -271,7 +271,7 @@ static int efm32x_read_info(struct flash_bank *bank,
efm32_info->family_data = &efm32_families[i]; efm32_info->family_data = &efm32_families[i];
} }
if (efm32_info->family_data == NULL) { if (!efm32_info->family_data) {
LOG_ERROR("Unknown MCU family %d", efm32_info->part_family); LOG_ERROR("Unknown MCU family %d", efm32_info->part_family);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -885,7 +885,7 @@ static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t old_count = count; uint32_t old_count = count;
count = (old_count | 3) + 1; count = (old_count | 3) + 1;
new_buffer = malloc(count); new_buffer = malloc(count);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory " LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer"); "for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
@ -1016,7 +1016,7 @@ static int efm32x_protect_check(struct flash_bank *bank)
return ret; return ret;
} }
assert(NULL != bank->sectors); assert(bank->sectors);
for (unsigned int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i); bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i);

View File

@ -43,12 +43,12 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct faux_flash_bank)); info = malloc(sizeof(struct faux_flash_bank));
if (info == NULL) { if (!info) {
LOG_ERROR("no memory for flash bank info"); LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL; return ERROR_FAIL;
} }
info->memory = malloc(bank->size); info->memory = malloc(bank->size);
if (info->memory == NULL) { if (!info->memory) {
free(info); free(info);
LOG_ERROR("no memory for flash bank info"); LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL; return ERROR_FAIL;
@ -68,7 +68,7 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
} }
info->target = get_target(CMD_ARGV[5]); info->target = get_target(CMD_ARGV[5]);
if (info->target == NULL) { if (!info->target) {
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]); LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
free(info->memory); free(info->memory);
free(info); free(info);

View File

@ -151,7 +151,7 @@ FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
fespi_info = malloc(sizeof(struct fespi_flash_bank)); fespi_info = malloc(sizeof(struct fespi_flash_bank));
if (fespi_info == NULL) { if (!fespi_info) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -986,7 +986,7 @@ static int fespi_probe(struct flash_bank *bank)
/* create and fill sectors array */ /* create and fill sectors array */
bank->num_sectors = fespi_info->dev->size_in_bytes / sectorsize; bank->num_sectors = fespi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -42,7 +42,7 @@ FLASH_BANK_COMMAND_HANDLER(jtagspi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct jtagspi_flash_bank)); info = malloc(sizeof(struct jtagspi_flash_bank));
if (info == NULL) { if (!info) {
LOG_ERROR("no memory for flash bank info"); LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -129,7 +129,7 @@ static int jtagspi_cmd(struct flash_bank *bank, uint8_t cmd,
lenb = DIV_ROUND_UP(len, 8); lenb = DIV_ROUND_UP(len, 8);
data_buf = malloc(lenb); data_buf = malloc(lenb);
if (lenb > 0) { if (lenb > 0) {
if (data_buf == NULL) { if (!data_buf) {
LOG_ERROR("no memory for spi buffer"); LOG_ERROR("no memory for spi buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -211,7 +211,7 @@ static int jtagspi_probe(struct flash_bank *bank)
/* create and fill sectors array */ /* create and fill sectors array */
bank->num_sectors = info->dev->size_in_bytes / sectorsize; bank->num_sectors = info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -882,9 +882,9 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
k_chip = kinetis_get_chip(target); k_chip = kinetis_get_chip(target);
if (k_chip == NULL) { if (!k_chip) {
k_chip = calloc(sizeof(struct kinetis_chip), 1); k_chip = calloc(sizeof(struct kinetis_chip), 1);
if (k_chip == NULL) { if (!k_chip) {
LOG_ERROR("No memory"); LOG_ERROR("No memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -915,11 +915,11 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
static void kinetis_free_driver_priv(struct flash_bank *bank) static void kinetis_free_driver_priv(struct flash_bank *bank)
{ {
struct kinetis_flash_bank *k_bank = bank->driver_priv; struct kinetis_flash_bank *k_bank = bank->driver_priv;
if (k_bank == NULL) if (!k_bank)
return; return;
struct kinetis_chip *k_chip = k_bank->k_chip; struct kinetis_chip *k_chip = k_bank->k_chip;
if (k_chip == NULL) if (!k_chip)
return; return;
k_chip->num_banks--; k_chip->num_banks--;
@ -985,7 +985,7 @@ static int kinetis_create_missing_banks(struct kinetis_chip *k_chip)
} }
bank = calloc(sizeof(struct flash_bank), 1); bank = calloc(sizeof(struct flash_bank), 1);
if (bank == NULL) if (!bank)
return ERROR_FAIL; return ERROR_FAIL;
bank->target = k_chip->target; bank->target = k_chip->target;
@ -1174,7 +1174,7 @@ COMMAND_HANDLER(kinetis_disable_wdog_handler)
struct target *target = get_current_target(CMD_CTX); struct target *target = get_current_target(CMD_CTX);
struct kinetis_chip *k_chip = kinetis_get_chip(target); struct kinetis_chip *k_chip = kinetis_get_chip(target);
if (k_chip == NULL) if (!k_chip)
return ERROR_FAIL; return ERROR_FAIL;
if (CMD_ARGC > 0) if (CMD_ARGC > 0)
@ -1428,7 +1428,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
k_bank = &(k_chip->banks[bank_idx]); k_bank = &(k_chip->banks[bank_idx]);
bank_iter = k_bank->bank; bank_iter = k_bank->bank;
if (bank_iter == NULL) { if (!bank_iter) {
LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx); LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx);
continue; continue;
} }
@ -1538,7 +1538,7 @@ static int kinetis_check_run_mode(struct kinetis_chip *k_chip)
uint8_t pmstat; uint8_t pmstat;
struct target *target; struct target *target;
if (k_chip == NULL) { if (!k_chip) {
LOG_ERROR("Chip not probed."); LOG_ERROR("Chip not probed.");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -1840,7 +1840,7 @@ static int kinetis_write_inner(struct flash_bank *bank, const uint8_t *buffer,
uint32_t old_count = count; uint32_t old_count = count;
count = (old_count | 3) + 1; count = (old_count | 3) + 1;
new_buffer = malloc(count); new_buffer = malloc(count);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory " LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer"); "for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
@ -2896,7 +2896,7 @@ COMMAND_HANDLER(kinetis_nvm_partition)
} }
switch (sz_type) { switch (sz_type) {
case SHOW_INFO: case SHOW_INFO:
if (k_chip == NULL) { if (!k_chip) {
LOG_ERROR("Chip not probed."); LOG_ERROR("Chip not probed.");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -945,7 +945,7 @@ COMMAND_HANDLER(kinetis_ke_securing_test)
if (result != ERROR_OK) if (result != ERROR_OK)
return result; return result;
assert(bank != NULL); assert(bank);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -1046,7 +1046,7 @@ static int kinetis_ke_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t old_count = count; uint32_t old_count = count;
count = (old_count | 3) + 1; count = (old_count | 3) + 1;
new_buffer = malloc(count); new_buffer = malloc(count);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory " LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer"); "for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;

View File

@ -66,7 +66,7 @@ FLASH_BANK_COMMAND_HANDLER(lpcspifi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
lpcspifi_info = malloc(sizeof(struct lpcspifi_flash_bank)); lpcspifi_info = malloc(sizeof(struct lpcspifi_flash_bank));
if (lpcspifi_info == NULL) { if (!lpcspifi_info) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -894,7 +894,7 @@ static int lpcspifi_probe(struct flash_bank *bank)
/* create and fill sectors array */ /* create and fill sectors array */
bank->num_sectors = lpcspifi_info->dev->size_in_bytes / sectorsize; bank->num_sectors = lpcspifi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -328,7 +328,7 @@ static int mdr_write(struct flash_bank *bank, const uint8_t *buffer,
int rem = count % 4; int rem = count % 4;
if (rem) { if (rem) {
new_buffer = malloc(count + rem); new_buffer = malloc(count + rem);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory for padding buffer"); LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -882,7 +882,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
/* create and fill sectors array */ /* create and fill sectors array */
bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize; bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -938,7 +938,7 @@ FLASH_BANK_COMMAND_HANDLER(mrvlqspi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
mrvlqspi_info = malloc(sizeof(struct mrvlqspi_flash_bank)); mrvlqspi_info = malloc(sizeof(struct mrvlqspi_flash_bank));
if (mrvlqspi_info == NULL) { if (!mrvlqspi_info) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -335,7 +335,7 @@ static int msp432_init(struct flash_bank *bank)
} }
/* Check for working area to use for flash helper algorithm */ /* Check for working area to use for flash helper algorithm */
if (NULL != msp432_bank->working_area) if (msp432_bank->working_area)
target_free_working_area(target, msp432_bank->working_area); target_free_working_area(target, msp432_bank->working_area);
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE, retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
&msp432_bank->working_area); &msp432_bank->working_area);
@ -569,7 +569,7 @@ FLASH_BANK_COMMAND_HANDLER(msp432_flash_bank_command)
/* Create shared private struct for flash banks */ /* Create shared private struct for flash banks */
msp432_bank = malloc(sizeof(struct msp432_bank)); msp432_bank = malloc(sizeof(struct msp432_bank));
if (NULL == msp432_bank) if (!msp432_bank)
return ERROR_FAIL; return ERROR_FAIL;
/* Initialize private flash information */ /* Initialize private flash information */
@ -907,7 +907,7 @@ static int msp432_probe(struct flash_bank *bank)
if (num_sectors > 0) { if (num_sectors > 0) {
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors) if (!bank->sectors)
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -933,7 +933,7 @@ static int msp432_probe(struct flash_bank *bank)
if (is_main && MSP432P4 == msp432_bank->family_type) { if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */ /* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1); struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
if (NULL == info) if (!info)
return ERROR_FAIL; return ERROR_FAIL;
/* Create a name for the info bank, append "_1" to main name */ /* Create a name for the info bank, append "_1" to main name */

View File

@ -1394,7 +1394,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer,
int rem = count % 16; int rem = count % 16;
if (rem) { if (rem) {
new_buffer = malloc(count + 16 - rem); new_buffer = malloc(count + 16 - rem);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("Odd number of words to write and no memory for padding buffer"); LOG_ERROR("Odd number of words to write and no memory for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -293,7 +293,7 @@ static bool nrf5_bank_is_probed(const struct flash_bank *bank)
{ {
struct nrf5_bank *nbank = bank->driver_priv; struct nrf5_bank *nbank = bank->driver_priv;
assert(nbank != NULL); assert(nbank);
return nbank->probed; return nbank->probed;
} }
@ -444,7 +444,7 @@ static int nrf5_protect_check_clenr0(struct flash_bank *bank)
struct nrf5_bank *nbank = bank->driver_priv; struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip; struct nrf5_info *chip = nbank->chip;
assert(chip != NULL); assert(chip);
res = target_read_u32(chip->target, NRF51_FICR_CLENR0, res = target_read_u32(chip->target, NRF51_FICR_CLENR0,
&clenr0); &clenr0);
@ -474,7 +474,7 @@ static int nrf5_protect_check_bprot(struct flash_bank *bank)
struct nrf5_bank *nbank = bank->driver_priv; struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip; struct nrf5_info *chip = nbank->chip;
assert(chip != NULL); assert(chip);
static uint32_t nrf5_bprot_offsets[4] = { 0x600, 0x604, 0x610, 0x614 }; static uint32_t nrf5_bprot_offsets[4] = { 0x600, 0x604, 0x610, 0x614 };
uint32_t bprot_reg = 0; uint32_t bprot_reg = 0;
@ -505,7 +505,7 @@ static int nrf5_protect_check(struct flash_bank *bank)
struct nrf5_bank *nbank = bank->driver_priv; struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip; struct nrf5_info *chip = nbank->chip;
assert(chip != NULL); assert(chip);
if (chip->features & NRF5_FEATURE_BPROT) if (chip->features & NRF5_FEATURE_BPROT)
return nrf5_protect_check_bprot(bank); return nrf5_protect_check_bprot(bank);
@ -1133,7 +1133,7 @@ static void nrf5_free_driver_priv(struct flash_bank *bank)
{ {
struct nrf5_bank *nbank = bank->driver_priv; struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip; struct nrf5_info *chip = nbank->chip;
if (chip == NULL) if (!chip)
return; return;
chip->refcount--; chip->refcount--;
@ -1197,7 +1197,7 @@ FLASH_BANK_COMMAND_HANDLER(nrf5_flash_bank_command)
nbank = &chip->bank[1]; nbank = &chip->bank[1];
break; break;
} }
assert(nbank != NULL); assert(nbank);
chip->refcount++; chip->refcount++;
nbank->chip = chip; nbank->chip = chip;
@ -1218,7 +1218,7 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
if (res != ERROR_OK) if (res != ERROR_OK)
return res; return res;
assert(bank != NULL); assert(bank);
struct nrf5_info *chip; struct nrf5_info *chip;
@ -1265,7 +1265,7 @@ COMMAND_HANDLER(nrf5_handle_info_command)
if (res != ERROR_OK) if (res != ERROR_OK)
return res; return res;
assert(bank != NULL); assert(bank);
struct nrf5_info *chip; struct nrf5_info *chip;

View File

@ -1386,7 +1386,7 @@ static int numicro_writeblock(struct flash_bank *bank, const uint8_t *buffer,
init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* number of words to program */ init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* number of words to program */
struct armv7m_common *armv7m = target_to_armv7m(target); struct armv7m_common *armv7m = target_to_armv7m(target);
if (armv7m == NULL) { if (!armv7m) {
/* something is very wrong if armv7m is NULL */ /* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target"); LOG_ERROR("unable to get armv7m target");
return retval; return retval;

View File

@ -515,7 +515,7 @@ static int pic32mx_write_block(struct flash_bank *bank, const uint8_t *buffer,
uint8_t *new_buffer = NULL; uint8_t *new_buffer = NULL;
if (row_offset && (count >= (row_size / 4))) { if (row_offset && (count >= (row_size / 4))) {
new_buffer = malloc(buffer_size); new_buffer = malloc(buffer_size);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -320,7 +320,7 @@ static int psoc4_sysreq(struct flash_bank *bank, uint8_t cmd,
sysreq_wait_algorithm->address + sysreq_wait_algorithm->size); sysreq_wait_algorithm->address + sysreq_wait_algorithm->size);
struct armv7m_common *armv7m = target_to_armv7m(target); struct armv7m_common *armv7m = target_to_armv7m(target);
if (armv7m == NULL) { if (!armv7m) {
/* something is very wrong if armv7m is NULL */ /* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target"); LOG_ERROR("unable to get armv7m target");
retval = ERROR_FAIL; retval = ERROR_FAIL;
@ -576,7 +576,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, unsigned int first,
int prot_sz = num_bits / 8; int prot_sz = num_bits / 8;
sysrq_buffer = malloc(param_sz + prot_sz); sysrq_buffer = malloc(param_sz + prot_sz);
if (sysrq_buffer == NULL) { if (!sysrq_buffer) {
LOG_ERROR("no memory for row buffer"); LOG_ERROR("no memory for row buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -658,7 +658,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer,
return retval; return retval;
sysrq_buffer = malloc(param_sz + psoc4_info->row_size); sysrq_buffer = malloc(param_sz + psoc4_info->row_size);
if (sysrq_buffer == NULL) { if (!sysrq_buffer) {
LOG_ERROR("no memory for row buffer"); LOG_ERROR("no memory for row buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -833,7 +833,7 @@ static int psoc4_probe(struct flash_bank *bank)
bank->size = num_rows * row_size; bank->size = num_rows * row_size;
bank->num_sectors = num_rows; bank->num_sectors = num_rows;
bank->sectors = alloc_block_array(0, row_size, num_rows); bank->sectors = alloc_block_array(0, row_size, num_rows);
if (bank->sectors == NULL) if (!bank->sectors)
return ERROR_FAIL; return ERROR_FAIL;
LOG_DEBUG("flash bank set %" PRIu32 " rows", num_rows); LOG_DEBUG("flash bank set %" PRIu32 " rows", num_rows);

View File

@ -1113,7 +1113,7 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
struct target_memory_check_block *block_array; struct target_memory_check_block *block_array;
block_array = malloc(num_sectors * sizeof(struct target_memory_check_block)); block_array = malloc(num_sectors * sizeof(struct target_memory_check_block));
if (block_array == NULL) if (!block_array)
return ERROR_FAIL; return ERROR_FAIL;
for (unsigned int i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {

View File

@ -99,7 +99,7 @@ int spi_sfdp(struct flash_bank *bank, struct flash_device *dev,
nph = ((header.revision >> 16) & 0xFF) + 1; nph = ((header.revision >> 16) & 0xFF) + 1;
LOG_DEBUG("parameter headers: %d", nph); LOG_DEBUG("parameter headers: %d", nph);
pheaders = malloc(sizeof(struct sfdp_phdr) * nph); pheaders = malloc(sizeof(struct sfdp_phdr) * nph);
if (pheaders == NULL) { if (!pheaders) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -119,7 +119,7 @@ int spi_sfdp(struct flash_bank *bank, struct flash_device *dev,
/* retrieve parameter table */ /* retrieve parameter table */
ptable = malloc(words << 2); ptable = malloc(words << 2);
if (ptable == NULL) { if (!ptable) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
retval = ERROR_FAIL; retval = ERROR_FAIL;
goto err; goto err;

View File

@ -511,7 +511,7 @@ static int sim3x_flash_write(struct flash_bank *bank, const uint8_t *buffer, uin
count++; count++;
new_buffer = malloc(count); new_buffer = malloc(count);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory " LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer"); "for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
@ -935,7 +935,7 @@ COMMAND_HANDLER(sim3x_mass_erase)
struct cortex_m_common *cortex_m = target_to_cm(target); struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap; struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
if (dap == NULL) { if (!dap) {
/* Used debug interface doesn't support direct DAP access */ /* Used debug interface doesn't support direct DAP access */
LOG_ERROR("mass_erase can't be used by this debug interface"); LOG_ERROR("mass_erase can't be used by this debug interface");
return ERROR_FAIL; return ERROR_FAIL;
@ -980,7 +980,7 @@ COMMAND_HANDLER(sim3x_lock)
struct cortex_m_common *cortex_m = target_to_cm(target); struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap; struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
if (dap == NULL) { if (!dap) {
/* Used debug interface doesn't support direct DAP access */ /* Used debug interface doesn't support direct DAP access */
LOG_INFO("Target can't by unlocked by this debug interface"); LOG_INFO("Target can't by unlocked by this debug interface");
@ -1052,7 +1052,7 @@ COMMAND_HANDLER(sim3x_lock)
LOG_ERROR("Unexpected lock word value"); LOG_ERROR("Unexpected lock word value");
/* SIM3X_AP_ID_VALUE is not checked */ /* SIM3X_AP_ID_VALUE is not checked */
if (dap == NULL) if (!dap)
LOG_INFO("Maybe this isn't a SiM3x MCU"); LOG_INFO("Maybe this isn't a SiM3x MCU");
return ERROR_FAIL; return ERROR_FAIL;

View File

@ -561,7 +561,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
* discrete accesses. */ * discrete accesses. */
if (count & 1) { if (count & 1) {
new_buffer = malloc(count + 1); new_buffer = malloc(count + 1);
if (new_buffer == NULL) { if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory for padding buffer"); LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -1179,7 +1179,7 @@ static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *c
return ERROR_FAIL; return ERROR_FAIL;
} }
if (rev_str != NULL) if (rev_str)
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str); command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", device_str, rev_id); command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", device_str, rev_id);

View File

@ -1412,7 +1412,7 @@ static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *c
return ERROR_FAIL; return ERROR_FAIL;
} }
if (rev_str != NULL) if (rev_str)
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str); command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04" PRIx16 ")", device_str, rev_id); command_print_sameline(cmd, "%s - Rev: unknown (0x%04" PRIx16 ")", device_str, rev_id);

View File

@ -879,7 +879,7 @@ static int stm32x_probe(struct flash_bank *bank)
bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024, bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024,
bank->num_sectors); bank->num_sectors);
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("failed to allocate bank sectors"); LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -896,7 +896,7 @@ static int stm32x_probe(struct flash_bank *bank)
bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024, bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024,
bank->num_prot_blocks); bank->num_prot_blocks);
if (bank->prot_blocks == NULL) { if (!bank->prot_blocks) {
LOG_ERROR("failed to allocate bank prot_block"); LOG_ERROR("failed to allocate bank prot_block");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -937,7 +937,7 @@ static int stm32x_get_info(struct flash_bank *bank, struct command_invocation *c
if (rev_id == info->revs[i].rev) if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str; rev_str = info->revs[i].str;
if (rev_str != NULL) { if (rev_str) {
command_print_sameline(cmd, "%s - Rev: %s", command_print_sameline(cmd, "%s - Rev: %s",
stm32x_info->part_info->device_str, rev_str); stm32x_info->part_info->device_str, rev_str);
} else { } else {

View File

@ -1603,7 +1603,7 @@ static int stm32l4_probe(struct flash_bank *bank)
bank->size = (flash_size_kb + gap_size_kb) * 1024; bank->size = (flash_size_kb + gap_size_kb) * 1024;
bank->num_sectors = num_pages; bank->num_sectors = num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("failed to allocate bank sectors"); LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -290,7 +290,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32lx_flash_bank_command)
stm32lx_info = calloc(1, sizeof(*stm32lx_info)); stm32lx_info = calloc(1, sizeof(*stm32lx_info));
/* Check allocation */ /* Check allocation */
if (stm32lx_info == NULL) { if (!stm32lx_info) {
LOG_ERROR("failed to allocate bank structure"); LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -503,7 +503,7 @@ static int stm32lx_write_half_pages(struct flash_bank *bank, const uint8_t *buff
} }
struct armv7m_common *armv7m = target_to_armv7m(target); struct armv7m_common *armv7m = target_to_armv7m(target);
if (armv7m == NULL) { if (!armv7m) {
/* something is very wrong if armv7m is NULL */ /* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target"); LOG_ERROR("unable to get armv7m target");
@ -842,7 +842,7 @@ static int stm32lx_probe(struct flash_bank *bank)
bank->base = base_address; bank->base = base_address;
bank->num_sectors = num_sectors; bank->num_sectors = num_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("failed to allocate bank sectors"); LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -889,7 +889,7 @@ static int stm32lx_get_info(struct flash_bank *bank, struct command_invocation *
if (rev_id == info->revs[i].rev) if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str; rev_str = info->revs[i].str;
if (rev_str != NULL) { if (rev_str) {
command_print_sameline(cmd, "%s - Rev: %s", info->device_str, rev_str); command_print_sameline(cmd, "%s - Rev: %s", info->device_str, rev_str);
} else { } else {
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", info->device_str, rev_id); command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", info->device_str, rev_id);

View File

@ -225,7 +225,7 @@ FLASH_BANK_COMMAND_HANDLER(stmqspi_flash_bank_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], io_base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], io_base);
stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank)); stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank));
if (stmqspi_info == NULL) { if (!stmqspi_info) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -754,7 +754,7 @@ COMMAND_HANDLER(stmqspi_handle_set)
bank->num_sectors = bank->num_sectors =
stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize; stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -2358,7 +2358,7 @@ static int stmqspi_probe(struct flash_bank *bank)
/* create and fill sectors array */ /* create and fill sectors array */
bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize; bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
retval = ERROR_FAIL; retval = ERROR_FAIL;
goto err; goto err;

View File

@ -144,7 +144,7 @@ FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank)); stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
if (stmsmi_info == NULL) { if (!stmsmi_info) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -600,7 +600,7 @@ static int stmsmi_probe(struct flash_bank *bank)
bank->num_sectors = bank->num_sectors =
stmsmi_info->dev->size_in_bytes / sectorsize; stmsmi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) { if (!sectors) {
LOG_ERROR("not enough memory"); LOG_ERROR("not enough memory");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -81,7 +81,7 @@ static int str9xpec_write_options(struct flash_bank *bank);
static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state) static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{ {
if (tap == NULL) if (!tap)
return ERROR_TARGET_INVALID; return ERROR_TARGET_INVALID;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) { if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
@ -1043,19 +1043,19 @@ COMMAND_HANDLER(str9xpec_handle_flash_enable_turbo_command)
/* remove arm core from chain - enter turbo mode */ /* remove arm core from chain - enter turbo mode */
tap0 = str9xpec_info->tap; tap0 = str9xpec_info->tap;
if (tap0 == NULL) { if (!tap0) {
/* things are *WRONG* */ /* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap0) invalid chain?"); command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
return ERROR_FAIL; return ERROR_FAIL;
} }
tap1 = tap0->next_tap; tap1 = tap0->next_tap;
if (tap1 == NULL) { if (!tap1) {
/* things are *WRONG* */ /* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap1) invalid chain?"); command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
return ERROR_FAIL; return ERROR_FAIL;
} }
tap2 = tap1->next_tap; tap2 = tap1->next_tap;
if (tap2 == NULL) { if (!tap2) {
/* things are *WRONG* */ /* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap2) invalid chain?"); command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
return ERROR_FAIL; return ERROR_FAIL;
@ -1089,7 +1089,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
str9xpec_info = bank->driver_priv; str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap; tap = str9xpec_info->tap;
if (tap == NULL) if (!tap)
return ERROR_FAIL; return ERROR_FAIL;
/* exit turbo mode via RESET */ /* exit turbo mode via RESET */

View File

@ -88,7 +88,7 @@ COMMAND_HANDLER(handle_flash_info_command)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (p != NULL) { if (p) {
int num_blocks; int num_blocks;
struct flash_sector *block_array; struct flash_sector *block_array;
@ -584,7 +584,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
uint32_t padding_at_end = aligned_end - end_addr; uint32_t padding_at_end = aligned_end - end_addr;
uint8_t *buffer = malloc(aligned_size); uint8_t *buffer = malloc(aligned_size);
if (buffer == NULL) if (!buffer)
return ERROR_FAIL; return ERROR_FAIL;
if (padding_at_start) { if (padding_at_start) {
@ -724,7 +724,7 @@ COMMAND_HANDLER(handle_flash_md_command)
} }
uint8_t *buffer = calloc(count, wordsize); uint8_t *buffer = calloc(count, wordsize);
if (buffer == NULL) { if (!buffer) {
command_print(CMD, "No memory for flash read buffer"); command_print(CMD, "No memory for flash read buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -799,7 +799,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
uint32_t padding_at_end = aligned_end - end_addr; uint32_t padding_at_end = aligned_end - end_addr;
buffer = malloc(aligned_size); buffer = malloc(aligned_size);
if (buffer == NULL) { if (!buffer) {
fileio_close(fileio); fileio_close(fileio);
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
@ -896,7 +896,7 @@ COMMAND_HANDLER(handle_flash_read_bank_command)
} }
buffer = malloc(length); buffer = malloc(length);
if (buffer == NULL) { if (!buffer) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -990,7 +990,7 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
"first %zu bytes of the file", length); "first %zu bytes of the file", length);
buffer_file = malloc(length); buffer_file = malloc(length);
if (buffer_file == NULL) { if (!buffer_file) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
fileio_close(fileio); fileio_close(fileio);
return ERROR_FAIL; return ERROR_FAIL;
@ -1011,7 +1011,7 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
} }
buffer_flash = malloc(length); buffer_flash = malloc(length);
if (buffer_flash == NULL) { if (!buffer_flash) {
LOG_ERROR("Out of memory"); LOG_ERROR("Out of memory");
free(buffer_file); free(buffer_file);
return ERROR_FAIL; return ERROR_FAIL;
@ -1262,14 +1262,14 @@ COMMAND_HANDLER(handle_flash_bank_command)
CMD_ARGC--; CMD_ARGC--;
struct target *target = get_target(CMD_ARGV[5]); struct target *target = get_target(CMD_ARGV[5]);
if (target == NULL) { if (!target) {
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]); LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
return ERROR_FAIL; return ERROR_FAIL;
} }
const char *driver_name = CMD_ARGV[0]; const char *driver_name = CMD_ARGV[0];
const struct flash_driver *driver = flash_driver_find_by_name(driver_name); const struct flash_driver *driver = flash_driver_find_by_name(driver_name);
if (NULL == driver) { if (!driver) {
/* no matching flash driver found */ /* no matching flash driver found */
LOG_ERROR("flash driver '%s' not found", driver_name); LOG_ERROR("flash driver '%s' not found", driver_name);
return ERROR_FAIL; return ERROR_FAIL;
@ -1283,7 +1283,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
} }
/* register flash specific commands */ /* register flash specific commands */
if (NULL != driver->commands) { if (driver->commands) {
int retval = register_commands(CMD_CTX, NULL, int retval = register_commands(CMD_CTX, NULL,
driver->commands); driver->commands);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
@ -1313,7 +1313,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
return retval; return retval;
} }
if (driver->usage == NULL) if (!driver->usage)
LOG_DEBUG("'%s' driver usage field missing", driver_name); LOG_DEBUG("'%s' driver usage field missing", driver_name);
flash_bank_add(c); flash_bank_add(c);

View File

@ -27,7 +27,7 @@ static struct flash_bank *virtual_get_master_bank(struct flash_bank *bank)
struct flash_bank *master_bank; struct flash_bank *master_bank;
master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv); master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv);
if (master_bank == NULL) if (!master_bank)
LOG_ERROR("master flash bank '%s' does not exist", (char *)bank->driver_priv); LOG_ERROR("master flash bank '%s' does not exist", (char *)bank->driver_priv);
return master_bank; return master_bank;
@ -37,7 +37,7 @@ static void virtual_update_bank_info(struct flash_bank *bank)
{ {
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
if (master_bank == NULL) if (!master_bank)
return; return;
/* update the info we do not have */ /* update the info we do not have */
@ -64,7 +64,7 @@ FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command)
const char *bank_name = CMD_ARGV[6]; const char *bank_name = CMD_ARGV[6];
struct flash_bank *master_bank = get_flash_bank_by_name_noprobe(bank_name); struct flash_bank *master_bank = get_flash_bank_by_name_noprobe(bank_name);
if (master_bank == NULL) { if (!master_bank) {
LOG_ERROR("master flash bank '%s' does not exist", bank_name); LOG_ERROR("master flash bank '%s' does not exist", bank_name);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -80,7 +80,7 @@ static int virtual_protect(struct flash_bank *bank, int set, unsigned int first,
{ {
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
return flash_driver_protect(master_bank, set, first, last); return flash_driver_protect(master_bank, set, first, last);
@ -90,7 +90,7 @@ static int virtual_protect_check(struct flash_bank *bank)
{ {
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
if (master_bank->driver->protect_check == NULL) if (master_bank->driver->protect_check == NULL)
@ -106,7 +106,7 @@ static int virtual_erase(struct flash_bank *bank, unsigned int first,
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */
@ -123,7 +123,7 @@ static int virtual_write(struct flash_bank *bank, const uint8_t *buffer,
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */
@ -139,7 +139,7 @@ static int virtual_probe(struct flash_bank *bank)
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */
@ -158,7 +158,7 @@ static int virtual_auto_probe(struct flash_bank *bank)
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */
@ -176,7 +176,7 @@ static int virtual_info(struct flash_bank *bank, struct command_invocation *cmd)
{ {
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
command_print_sameline(cmd, "%s driver for flash bank %s at " TARGET_ADDR_FMT, command_print_sameline(cmd, "%s driver for flash bank %s at " TARGET_ADDR_FMT,
@ -190,7 +190,7 @@ static int virtual_blank_check(struct flash_bank *bank)
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */
@ -207,7 +207,7 @@ static int virtual_flash_read(struct flash_bank *bank,
struct flash_bank *master_bank = virtual_get_master_bank(bank); struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval; int retval;
if (master_bank == NULL) if (!master_bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */ /* call master handler */

View File

@ -572,7 +572,7 @@ FLASH_BANK_COMMAND_HANDLER(xcf_flash_bank_command)
struct xcf_priv *priv; struct xcf_priv *priv;
priv = malloc(sizeof(struct xcf_priv)); priv = malloc(sizeof(struct xcf_priv));
if (priv == NULL) { if (!priv) {
LOG_ERROR("no memory for flash bank info"); LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -629,7 +629,7 @@ static int xcf_probe(struct flash_bank *bank)
} }
bank->sectors = malloc(bank->num_sectors * sizeof(struct flash_sector)); bank->sectors = malloc(bank->num_sectors * sizeof(struct flash_sector));
if (bank->sectors == NULL) { if (!bank->sectors) {
LOG_ERROR("No memory for sector table"); LOG_ERROR("No memory for sector table");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -941,7 +941,7 @@ static int xmc4xxx_get_info_command(struct flash_bank *bank, struct command_invo
} }
} }
if (rev_str != NULL) if (rev_str)
command_print_sameline(cmd, "%s - Rev: %s%s", dev_str, rev_str, prot_str); command_print_sameline(cmd, "%s - Rev: %s%s", dev_str, rev_str, prot_str);
else else
command_print_sameline(cmd, "%s - Rev: unknown (0x%01x)%s", dev_str, rev_id, prot_str); command_print_sameline(cmd, "%s - Rev: unknown (0x%01x)%s", dev_str, rev_id, prot_str);

View File

@ -118,7 +118,7 @@ static struct log_capture_state *command_log_capture_start(Jim_Interp *interp)
*/ */
static void command_log_capture_finish(struct log_capture_state *state) static void command_log_capture_finish(struct log_capture_state *state)
{ {
if (NULL == state) if (!state)
return; return;
log_remove_callback(tcl_output, state); log_remove_callback(tcl_output, state);
@ -175,7 +175,7 @@ static int workaround_createcommand(Jim_Interp *interp, const char *cmdName,
static int command_retval_set(Jim_Interp *interp, int retval) static int command_retval_set(Jim_Interp *interp, int retval)
{ {
int *return_retval = Jim_GetAssocData(interp, "retval"); int *return_retval = Jim_GetAssocData(interp, "retval");
if (return_retval != NULL) if (return_retval)
*return_retval = retval; *return_retval = retval;
return (retval == ERROR_OK) ? JIM_OK : retval; return (retval == ERROR_OK) ? JIM_OK : retval;
@ -213,7 +213,7 @@ static char **script_command_args_alloc(
unsigned argc, Jim_Obj * const *argv, unsigned *nwords) unsigned argc, Jim_Obj * const *argv, unsigned *nwords)
{ {
char **words = malloc(argc * sizeof(char *)); char **words = malloc(argc * sizeof(char *));
if (NULL == words) if (!words)
return NULL; return NULL;
unsigned i; unsigned i;
@ -234,7 +234,7 @@ struct command_context *current_command_context(Jim_Interp *interp)
{ {
/* grab the command context from the associated data */ /* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
if (NULL == cmd_ctx) { if (!cmd_ctx) {
/* Tcl can invoke commands directly instead of via command_run_line(). This would /* Tcl can invoke commands directly instead of via command_run_line(). This would
* happen when the Jim Tcl interpreter is provided by eCos or if we are running * happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script. * commands in a startup script.
@ -285,7 +285,7 @@ static struct command *command_new(struct command_context *cmd_ctx,
full_name); full_name);
struct command *c = calloc(1, sizeof(struct command)); struct command *c = calloc(1, sizeof(struct command));
if (NULL == c) if (!c)
return NULL; return NULL;
c->name = strdup(cr->name); c->name = strdup(cr->name);
@ -369,16 +369,16 @@ int __register_commands(struct command_context *cmd_ctx, const char *cmd_prefix,
const struct command_registration *cr = cmds + i; const struct command_registration *cr = cmds + i;
struct command *c = NULL; struct command *c = NULL;
if (NULL != cr->name) { if (cr->name) {
c = register_command(cmd_ctx, cmd_prefix, cr); c = register_command(cmd_ctx, cmd_prefix, cr);
if (NULL == c) { if (!c) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
break; break;
} }
c->jim_handler_data = data; c->jim_handler_data = data;
c->jim_override_target = override_target; c->jim_override_target = override_target;
} }
if (NULL != cr->chain) { if (cr->chain) {
if (cr->name) { if (cr->name) {
if (cmd_prefix) { if (cmd_prefix) {
char *new_prefix = alloc_printf("%s %s", cmd_prefix, cr->name); char *new_prefix = alloc_printf("%s %s", cmd_prefix, cr->name);
@ -670,7 +670,7 @@ int command_run_linef(struct command_context *context, const char *format, ...)
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
string = alloc_vprintf(format, ap); string = alloc_vprintf(format, ap);
if (string != NULL) { if (string) {
retval = command_run_line(context, string); retval = command_run_line(context, string);
free(string); free(string);
} }
@ -696,7 +696,7 @@ struct command_context *copy_command_context(struct command_context *context)
void command_done(struct command_context *cmd_ctx) void command_done(struct command_context *cmd_ctx)
{ {
if (NULL == cmd_ctx) if (!cmd_ctx)
return; return;
free(cmd_ctx); free(cmd_ctx);
@ -709,7 +709,7 @@ static int jim_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR; return JIM_ERR;
const char *file = Jim_GetString(argv[1], NULL); const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file); char *full_path = find_file(file);
if (full_path == NULL) if (!full_path)
return JIM_ERR; return JIM_ERR;
Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path)); Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path));
free(full_path); free(full_path);
@ -816,8 +816,8 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
/* If the match string occurs anywhere, we print out /* If the match string occurs anywhere, we print out
* stuff for this command. */ * stuff for this command. */
bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) || bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
((c->usage != NULL) && (strstr(c->usage, cmd_match) != NULL)) || ((c->usage) && (strstr(c->usage, cmd_match) != NULL)) ||
((c->help != NULL) && (strstr(c->help, cmd_match) != NULL)); ((c->help) && (strstr(c->help, cmd_match) != NULL));
if (is_match) { if (is_match) {
if (c->usage && strlen(c->usage) > 0) { if (c->usage && strlen(c->usage) > 0) {
@ -870,7 +870,7 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
} else } else
msg = alloc_printf("%s", c->help ? c->help : ""); msg = alloc_printf("%s", c->help ? c->help : "");
if (NULL != msg) { if (msg) {
command_help_show_wrap(msg, n + 3, n + 3); command_help_show_wrap(msg, n + 3, n + 3);
free(msg); free(msg);
} else } else
@ -899,7 +899,7 @@ COMMAND_HANDLER(handle_help_command)
} }
} }
if (cmd_match == NULL) { if (!cmd_match) {
LOG_ERROR("unable to build search string"); LOG_ERROR("unable to build search string");
return -ENOMEM; return -ENOMEM;
} }
@ -1286,7 +1286,7 @@ struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp
INIT_LIST_HEAD(context->help_list); INIT_LIST_HEAD(context->help_list);
/* Create a jim interpreter if we were not handed one */ /* Create a jim interpreter if we were not handed one */
if (interp == NULL) { if (!interp) {
/* Create an interpreter */ /* Create an interpreter */
interp = Jim_CreateInterp(); interp = Jim_CreateInterp();
/* Add all the Jim core commands */ /* Add all the Jim core commands */

View File

@ -111,7 +111,7 @@ FILE *open_file_from_path(const char *file, const char *mode)
return fopen(file, mode); return fopen(file, mode);
else { else {
char *full_path = find_file(file); char *full_path = find_file(file);
if (full_path == NULL) if (!full_path)
return NULL; return NULL;
FILE *fp = NULL; FILE *fp = NULL;
fp = fopen(full_path, mode); fp = fopen(full_path, mode);
@ -150,12 +150,12 @@ char *get_home_dir(const char *append_path)
{ {
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) { if (!home) {
#ifdef _WIN32 #ifdef _WIN32
home = getenv("USERPROFILE"); home = getenv("USERPROFILE");
if (home == NULL) { if (!home) {
char homepath[MAX_PATH]; char homepath[MAX_PATH];
char *drive = getenv("HOMEDRIVE"); char *drive = getenv("HOMEDRIVE");
@ -173,7 +173,7 @@ char *get_home_dir(const char *append_path)
#endif #endif
} }
if (home == NULL) if (!home)
return home; return home;
char *home_path; char *home_path;

View File

@ -199,7 +199,7 @@ int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
} }
if (puthere) if (puthere)
*puthere = o; *puthere = o;
if (o != NULL) if (o)
return JIM_OK; return JIM_OK;
else else
return JIM_ERR; return JIM_ERR;
@ -227,7 +227,7 @@ int jim_getopt_double(struct jim_getopt_info *goi, double *puthere)
Jim_Obj *o; Jim_Obj *o;
double _safe; double _safe;
if (puthere == NULL) if (!puthere)
puthere = &_safe; puthere = &_safe;
r = jim_getopt_obj(goi, &o); r = jim_getopt_obj(goi, &o);
@ -245,7 +245,7 @@ int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Jim_Obj *o; Jim_Obj *o;
jim_wide _safe; jim_wide _safe;
if (puthere == NULL) if (!puthere)
puthere = &_safe; puthere = &_safe;
r = jim_getopt_obj(goi, &o); r = jim_getopt_obj(goi, &o);
@ -260,7 +260,7 @@ int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struc
Jim_Obj *o; Jim_Obj *o;
int e; int e;
if (puthere == NULL) if (!puthere)
puthere = &_safe; puthere = &_safe;
e = jim_getopt_obj(goi, &o); e = jim_getopt_obj(goi, &o);
@ -284,7 +284,7 @@ int jim_getopt_enum(struct jim_getopt_info *goi, const char *const *lookup, int
Jim_Obj *o; Jim_Obj *o;
int e; int e;
if (puthere == NULL) if (!puthere)
puthere = &_safe; puthere = &_safe;
e = jim_getopt_obj(goi, &o); e = jim_getopt_obj(goi, &o);
if (e == JIM_OK) if (e == JIM_OK)

View File

@ -108,7 +108,7 @@ static void log_puts(enum log_levels level,
} }
f = strrchr(file, '/'); f = strrchr(file, '/');
if (f != NULL) if (f)
file = f + 1; file = f + 1;
if (strlen(string) > 0) { if (strlen(string) > 0) {
@ -163,7 +163,7 @@ void log_printf(enum log_levels level,
va_start(ap, format); va_start(ap, format);
string = alloc_vprintf(format, ap); string = alloc_vprintf(format, ap);
if (string != NULL) { if (string) {
log_puts(level, file, line, function, string); log_puts(level, file, line, function, string);
free(string); free(string);
} }
@ -240,7 +240,7 @@ COMMAND_HANDLER(handle_log_output_command)
} }
if (CMD_ARGC == 1) { if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w"); FILE *file = fopen(CMD_ARGV[0], "w");
if (file == NULL) { if (!file) {
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]); LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -287,7 +287,7 @@ void log_init(void)
/* set defaults for daemon configuration, /* set defaults for daemon configuration,
* if not set by cmdline or cfgfile */ * if not set by cmdline or cfgfile */
char *debug_env = getenv("OPENOCD_DEBUG_LEVEL"); char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
if (NULL != debug_env) { if (debug_env) {
int value; int value;
int retval = parse_int(debug_env, &value); int retval = parse_int(debug_env, &value);
if (retval == ERROR_OK && if (retval == ERROR_OK &&
@ -296,7 +296,7 @@ void log_init(void)
debug_level = value; debug_level = value;
} }
if (log_output == NULL) if (!log_output)
log_output = stderr; log_output = stderr;
start = last_time = timeval_ms(); start = last_time = timeval_ms();
@ -322,7 +322,7 @@ int log_add_callback(log_callback_fn fn, void *priv)
/* alloc memory, it is safe just to return in case of an error, no need for the caller to /* alloc memory, it is safe just to return in case of an error, no need for the caller to
*check this */ *check this */
cb = malloc(sizeof(struct log_callback)); cb = malloc(sizeof(struct log_callback));
if (cb == NULL) if (!cb)
return ERROR_BUF_TOO_SMALL; return ERROR_BUF_TOO_SMALL;
/* add item to the beginning of the linked list */ /* add item to the beginning of the linked list */
@ -367,7 +367,7 @@ char *alloc_vprintf(const char *fmt, va_list ap)
* other code depend on that. They should be probably be fixed, but for * other code depend on that. They should be probably be fixed, but for
* now reserve the extra byte. */ * now reserve the extra byte. */
string = malloc(len + 2); string = malloc(len + 2);
if (string == NULL) if (!string)
return NULL; return NULL;
/* do the real work */ /* do the real work */

View File

@ -75,7 +75,7 @@ static char *find_exe_path(void)
do { do {
#if IS_WIN32 && !IS_CYGWIN #if IS_WIN32 && !IS_CYGWIN
exepath = malloc(MAX_PATH); exepath = malloc(MAX_PATH);
if (exepath == NULL) if (!exepath)
break; break;
GetModuleFileName(NULL, exepath, MAX_PATH); GetModuleFileName(NULL, exepath, MAX_PATH);
@ -87,7 +87,7 @@ static char *find_exe_path(void)
#elif IS_DARWIN #elif IS_DARWIN
exepath = malloc(PROC_PIDPATHINFO_MAXSIZE); exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
if (exepath == NULL) if (!exepath)
break; break;
if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) { if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
free(exepath); free(exepath);
@ -99,7 +99,7 @@ static char *find_exe_path(void)
#define PATH_MAX 1024 #define PATH_MAX 1024
#endif #endif
char *path = malloc(PATH_MAX); char *path = malloc(PATH_MAX);
if (path == NULL) if (!path)
break; break;
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t size = PATH_MAX; size_t size = PATH_MAX;
@ -117,14 +117,14 @@ static char *find_exe_path(void)
#elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */ #elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */
/* Try Unices in order of likelihood. */ /* Try Unices in order of likelihood. */
exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */ exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */
if (exepath == NULL) if (!exepath)
exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */ exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */
if (exepath == NULL) if (!exepath)
exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */ exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */
#endif #endif
} while (0); } while (0);
if (exepath != NULL) { if (exepath) {
/* Strip executable file name, leaving path */ /* Strip executable file name, leaving path */
*strrchr(exepath, '/') = '\0'; *strrchr(exepath, '/') = '\0';
} else { } else {
@ -163,7 +163,7 @@ static char *find_relative_path(const char *from, const char *to)
if (from[0] != '/') if (from[0] != '/')
i++; i++;
char *next = strchr(from, '/'); char *next = strchr(from, '/');
if (next == NULL) if (!next)
break; break;
from = next + 1; from = next + 1;
} }

View File

@ -33,7 +33,7 @@
void *clear_malloc(size_t size) void *clear_malloc(size_t size)
{ {
void *t = malloc(size); void *t = malloc(size);
if (t != NULL) if (t)
memset(t, 0x00, size); memset(t, 0x00, size);
return t; return t;
} }
@ -41,7 +41,7 @@ void *clear_malloc(size_t size)
void *fill_malloc(size_t size) void *fill_malloc(size_t size)
{ {
void *t = malloc(size); void *t = malloc(size);
if (t != NULL) { if (t) {
/* We want to initialize memory to some known bad state. /* We want to initialize memory to some known bad state.
* 0 and 0xff yields 0 and -1 as integers, which often * 0 and 0xff yields 0 and -1 as integers, which often
* have meaningful values. 0x5555... is not often a valid * have meaningful values. 0x5555... is not often a valid
@ -124,7 +124,7 @@ char *strndup(const char *s, size_t n)
size_t len = strnlen(s, n); size_t len = strnlen(s, n);
char *new = malloc(len + 1); char *new = malloc(len + 1);
if (new == NULL) if (!new)
return NULL; return NULL;
new[len] = '\0'; new[len] = '\0';
@ -148,7 +148,7 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
/* calculate how long we need to wait in milliseconds */ /* calculate how long we need to wait in milliseconds */
if (tv == NULL) if (!tv)
ms_total = INFINITE; ms_total = INFINITE;
else { else {
ms_total = tv->tv_sec * 1000; ms_total = tv->tv_sec * 1000;

View File

@ -43,7 +43,7 @@ static int jim_newtap_expected_id(struct jim_nvp *n, struct jim_getopt_info *goi
unsigned expected_len = sizeof(uint32_t) * tap->expected_ids_cnt; unsigned expected_len = sizeof(uint32_t) * tap->expected_ids_cnt;
uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t)); uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
if (new_expected_ids == NULL) { if (!new_expected_ids) {
Jim_SetResultFormatted(goi->interp, "no memory"); Jim_SetResultFormatted(goi->interp, "no memory");
return JIM_ERR; return JIM_ERR;
} }

View File

@ -2215,24 +2215,24 @@ static int aice_execute_custom_script(const char *script)
bool set_op; bool set_op;
script_fd = fopen(script, "r"); script_fd = fopen(script, "r");
if (script_fd == NULL) { if (!script_fd) {
return ERROR_FAIL; return ERROR_FAIL;
} else { } else {
while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) { while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
/* execute operations */ /* execute operations */
set_op = false; set_op = false;
op_str = strstr(line_buffer, "set"); op_str = strstr(line_buffer, "set");
if (op_str != NULL) { if (op_str) {
set_op = true; set_op = true;
goto get_reset_type; goto get_reset_type;
} }
op_str = strstr(line_buffer, "clear"); op_str = strstr(line_buffer, "clear");
if (op_str == NULL) if (!op_str)
continue; continue;
get_reset_type: get_reset_type:
reset_str = strstr(op_str, "srst"); reset_str = strstr(op_str, "srst");
if (reset_str != NULL) { if (reset_str) {
if (set_op) if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST; write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST;
else else
@ -2240,7 +2240,7 @@ get_reset_type:
goto get_delay; goto get_delay;
} }
reset_str = strstr(op_str, "dbgi"); reset_str = strstr(op_str, "dbgi");
if (reset_str != NULL) { if (reset_str) {
if (set_op) if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI; write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI;
else else
@ -2248,7 +2248,7 @@ get_reset_type:
goto get_delay; goto get_delay;
} }
reset_str = strstr(op_str, "trst"); reset_str = strstr(op_str, "trst");
if (reset_str != NULL) { if (reset_str) {
if (set_op) if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST; write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST;
else else
@ -2732,7 +2732,7 @@ static int aice_usb_reset(void)
return ERROR_FAIL; return ERROR_FAIL;
/* issue TRST */ /* issue TRST */
if (custom_trst_script == NULL) { if (!custom_trst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL, if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK) AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -2755,7 +2755,7 @@ static int aice_issue_srst(uint32_t coreid)
/* After issuing srst, target will be running. So we need to restore EDM_CTL. */ /* After issuing srst, target will be running. So we need to restore EDM_CTL. */
aice_restore_edm_registers(coreid); aice_restore_edm_registers(coreid);
if (custom_srst_script == NULL) { if (!custom_srst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL, if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK) AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -2799,7 +2799,7 @@ static int aice_issue_reset_hold(uint32_t coreid)
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4)); aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4));
/* issue restart */ /* issue restart */
if (custom_restart_script == NULL) { if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL, if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK) AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -2819,7 +2819,7 @@ static int aice_issue_reset_hold(uint32_t coreid)
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status | 0x4); aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status | 0x4);
/* issue restart again */ /* issue restart again */
if (custom_restart_script == NULL) { if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL, if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK) AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -3721,7 +3721,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
/* init strtok() */ /* init strtok() */
command_str = strtok(command_sequence, ";"); command_str = strtok(command_sequence, ";");
if (command_str == NULL) if (!command_str)
return ERROR_OK; return ERROR_OK;
do { do {
@ -3740,14 +3740,14 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
reg_name_0 = strstr(command_str, "gen_port0"); reg_name_0 = strstr(command_str, "gen_port0");
reg_name_1 = strstr(command_str, "gen_port1"); reg_name_1 = strstr(command_str, "gen_port1");
if (reg_name_0 != NULL) { if (reg_name_0) {
data_value = strtoul(reg_name_0 + 9, NULL, 0); data_value = strtoul(reg_name_0 + 9, NULL, 0);
if (aice_write_misc(coreid, if (aice_write_misc(coreid,
NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK) NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
} else if (reg_name_1 != NULL) { } else if (reg_name_1) {
data_value = strtoul(reg_name_1 + 9, NULL, 0); data_value = strtoul(reg_name_1 + 9, NULL, 0);
if (aice_write_misc(coreid, if (aice_write_misc(coreid,
@ -3763,7 +3763,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
/* update command_str */ /* update command_str */
command_str = strtok(NULL, ";"); command_str = strtok(NULL, ";");
} while (command_str != NULL); } while (command_str);
return ERROR_OK; return ERROR_OK;
} }

View File

@ -66,7 +66,7 @@ void jtag_queue_command(struct jtag_command *cmd)
cmd->next = NULL; cmd->next = NULL;
struct jtag_command **last_cmd = next_command_pointer; struct jtag_command **last_cmd = next_command_pointer;
assert(NULL != last_cmd); assert(last_cmd);
assert(NULL == *last_cmd); assert(NULL == *last_cmd);
*last_cmd = cmd; *last_cmd = cmd;

View File

@ -278,7 +278,7 @@ struct jtag_tap *jtag_tap_next_enabled(struct jtag_tap *p)
const char *jtag_tap_name(const struct jtag_tap *tap) const char *jtag_tap_name(const struct jtag_tap *tap)
{ {
return (tap == NULL) ? "(unknown)" : tap->dotted_name; return (!tap) ? "(unknown)" : tap->dotted_name;
} }
@ -286,7 +286,7 @@ int jtag_register_event_callback(jtag_event_handler_t callback, void *priv)
{ {
struct jtag_event_callback **callbacks_p = &jtag_event_callbacks; struct jtag_event_callback **callbacks_p = &jtag_event_callbacks;
if (callback == NULL) if (!callback)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) { if (*callbacks_p) {
@ -307,7 +307,7 @@ int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
{ {
struct jtag_event_callback **p = &jtag_event_callbacks, *temp; struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
if (callback == NULL) if (!callback)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
while (*p) { while (*p) {
@ -395,7 +395,7 @@ void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state) tap_state_t state)
{ {
assert(out_bits != NULL); assert(out_bits);
assert(state != TAP_RESET); assert(state != TAP_RESET);
jtag_prelude(state); jtag_prelude(state);
@ -468,7 +468,7 @@ void jtag_add_dr_scan(struct jtag_tap *active,
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state) tap_state_t state)
{ {
assert(out_bits != NULL); assert(out_bits);
assert(state != TAP_RESET); assert(state != TAP_RESET);
jtag_prelude(state); jtag_prelude(state);
@ -919,9 +919,9 @@ static int jtag_check_value_inner(uint8_t *captured, uint8_t *in_check_value,
void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask) void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask)
{ {
assert(field->in_value != NULL); assert(field->in_value);
if (value == NULL) { if (!value) {
/* no checking to do */ /* no checking to do */
return; return;
} }
@ -934,7 +934,7 @@ void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *ma
int default_interface_jtag_execute_queue(void) int default_interface_jtag_execute_queue(void)
{ {
if (NULL == jtag) { if (!jtag) {
LOG_ERROR("No JTAG interface configured yet. " LOG_ERROR("No JTAG interface configured yet. "
"Issue 'init' command in startup scripts " "Issue 'init' command in startup scripts "
"before communicating with targets."); "before communicating with targets.");
@ -1230,7 +1230,7 @@ static int jtag_examine_chain(void)
max_taps++; max_taps++;
uint8_t *idcode_buffer = calloc(4, max_taps); uint8_t *idcode_buffer = calloc(4, max_taps);
if (idcode_buffer == NULL) if (!idcode_buffer)
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
/* DR scan to collect BYPASS or IDCODE register contents. /* DR scan to collect BYPASS or IDCODE register contents.
@ -1255,7 +1255,7 @@ static int jtag_examine_chain(void)
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32); uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
/* No predefined TAP? Auto-probe. */ /* No predefined TAP? Auto-probe. */
if (tap == NULL) { if (!tap) {
/* Is there another TAP? */ /* Is there another TAP? */
if (jtag_idcode_is_final(idcode)) if (jtag_idcode_is_final(idcode))
break; break;
@ -1355,7 +1355,7 @@ static int jtag_validate_ircapture(void)
total_ir_length += 2; total_ir_length += 2;
ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8)); ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8));
if (ir_test == NULL) if (!ir_test)
return ERROR_FAIL; return ERROR_FAIL;
/* after this scan, all TAPs will capture BYPASS instructions */ /* after this scan, all TAPs will capture BYPASS instructions */
@ -1377,7 +1377,7 @@ static int jtag_validate_ircapture(void)
for (;; ) { for (;; ) {
tap = jtag_tap_next_enabled(tap); tap = jtag_tap_next_enabled(tap);
if (tap == NULL) if (!tap)
break; break;
/* If we're autoprobing, guess IR lengths. They must be at /* If we're autoprobing, guess IR lengths. They must be at
@ -1528,7 +1528,7 @@ int adapter_init(struct command_context *cmd_ctx)
return retval; return retval;
jtag = adapter_driver; jtag = adapter_driver;
if (jtag->speed == NULL) { if (!jtag->speed) {
LOG_INFO("This adapter doesn't support configurable speed"); LOG_INFO("This adapter doesn't support configurable speed");
return ERROR_OK; return ERROR_OK;
} }
@ -1574,7 +1574,7 @@ int jtag_init_inner(struct command_context *cmd_ctx)
LOG_DEBUG("Init JTAG chain"); LOG_DEBUG("Init JTAG chain");
tap = jtag_tap_next_enabled(NULL); tap = jtag_tap_next_enabled(NULL);
if (tap == NULL) { if (!tap) {
/* Once JTAG itself is properly set up, and the scan chain /* Once JTAG itself is properly set up, and the scan chain
* isn't absurdly large, IDCODE autoprobe should work fine. * isn't absurdly large, IDCODE autoprobe should work fine.
* *
@ -1885,7 +1885,7 @@ bool jtag_will_verify_capture_ir(void)
int jtag_power_dropout(int *dropout) int jtag_power_dropout(int *dropout)
{ {
if (jtag == NULL) { if (!jtag) {
/* TODO: as the jtag interface is not valid all /* TODO: as the jtag interface is not valid all
* we can do at the moment is exit OpenOCD */ * we can do at the moment is exit OpenOCD */
LOG_ERROR("No Valid JTAG Interface Configured."); LOG_ERROR("No Valid JTAG Interface Configured.");

View File

@ -103,7 +103,7 @@ static int armjtagew_execute_queue(void)
enum scan_type type; enum scan_type type;
uint8_t *buffer; uint8_t *buffer;
while (cmd != NULL) { while (cmd) {
switch (cmd->type) { switch (cmd->type) {
case JTAG_RUNTEST: case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i", LOG_DEBUG_IO("runtest %i cycles, end in %i",

View File

@ -168,7 +168,7 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
else else
tdo_req = 0; tdo_req = 0;
if (field->out_value == NULL) { if (!field->out_value) {
/* just send zeros and request data from TDO */ /* just send zeros and request data from TDO */
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
bitq_io(0, 0, tdo_req); bitq_io(0, 0, tdo_req);

View File

@ -285,7 +285,7 @@ static bool read_and_discard_all_data(const int fd)
static int buspirate_init(void) static int buspirate_init(void)
{ {
if (buspirate_port == NULL) { if (!buspirate_port) {
LOG_ERROR("You need to specify the serial port!"); LOG_ERROR("You need to specify the serial port!");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -466,7 +466,7 @@ COMMAND_HANDLER(buspirate_handle_port_command)
if (CMD_ARGC < 1) if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
if (buspirate_port == NULL) if (!buspirate_port)
buspirate_port = strdup(CMD_ARGV[0]); buspirate_port = strdup(CMD_ARGV[0]);
return ERROR_OK; return ERROR_OK;

View File

@ -269,7 +269,7 @@ static int cmsis_dap_open(void)
const struct cmsis_dap_backend *backend = NULL; const struct cmsis_dap_backend *backend = NULL;
struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap)); struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap));
if (dap == NULL) { if (!dap) {
LOG_ERROR("unable to allocate memory"); LOG_ERROR("unable to allocate memory");
return ERROR_FAIL; 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"); LOG_ERROR("unable to find a matching CMSIS-DAP device");
free(dap); free(dap);
return ERROR_FAIL; 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) | (tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) |
(s_len == 64 ? 0 : s_len); (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); bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len);
else else
memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8)); memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8));
queued_seq_buf_end += cmd_len; 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++]; struct pending_scan_result *scan = &pending_scan_results[pending_scan_result_count++];
scan->first = queued_seq_tdo_ptr; scan->first = queued_seq_tdo_ptr;
queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8); 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; struct jtag_command *cmd = jtag_command_queue;
while (cmd != NULL) { while (cmd) {
cmsis_dap_execute_command(cmd); cmsis_dap_execute_command(cmd);
cmd = cmd->next; cmd = cmd->next;
} }

View File

@ -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)); LOG_WARNING("could not claim interface: %s", libusb_strerror(err));
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data)); dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
if (dap->bdata == NULL) { if (!dap->bdata) {
LOG_ERROR("unable to allocate memory"); LOG_ERROR("unable to allocate memory");
libusb_release_interface(dev_handle, interface_num); libusb_release_interface(dev_handle, interface_num);
libusb_close(dev_handle); 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->bdata->interface = interface_num;
dap->packet_buffer = malloc(dap->packet_buffer_size); dap->packet_buffer = malloc(dap->packet_buffer_size);
if (dap->packet_buffer == NULL) { if (!dap->packet_buffer) {
LOG_ERROR("unable to allocate memory"); LOG_ERROR("unable to allocate memory");
cmsis_dap_usb_close(dap); cmsis_dap_usb_close(dap);
return ERROR_FAIL; 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) static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
{ {
uint8_t *buf = malloc(pkt_sz); uint8_t *buf = malloc(pkt_sz);
if (buf == NULL) { if (!buf) {
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -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); devs = hid_enumerate(0x0, 0x0);
cur_dev = devs; cur_dev = devs;
while (NULL != cur_dev) { while (cur_dev) {
bool found = false; bool found = false;
if (0 == vids[0]) { 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", LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
cur_dev->vendor_id, cur_dev->product_id); cur_dev->vendor_id, cur_dev->product_id);
} else if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) { } 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) { if (found) {
/* check serial number matches if given */ /* check serial number matches if given */
if (serial == NULL) if (!serial)
break; break;
if (cur_dev->serial_number != NULL) { if (cur_dev->serial_number) {
size_t len = (strlen(serial) + 1) * sizeof(wchar_t); size_t len = (strlen(serial) + 1) * sizeof(wchar_t);
wchar_t *wserial = malloc(len); wchar_t *wserial = malloc(len);
mbstowcs(wserial, serial, 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; cur_dev = cur_dev->next;
} }
if (NULL != cur_dev) { if (cur_dev) {
target_vid = cur_dev->vendor_id; target_vid = cur_dev->vendor_id;
target_pid = cur_dev->product_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)); dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
if (dap->bdata == NULL) { if (!dap->bdata) {
LOG_ERROR("unable to allocate memory"); LOG_ERROR("unable to allocate memory");
return ERROR_FAIL; 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); dev = hid_open_path(cur_dev->path);
hid_free_enumeration(devs); 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); LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
return ERROR_FAIL; 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; unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE;
uint8_t *buf = malloc(packet_buffer_size); uint8_t *buf = malloc(packet_buffer_size);
if (buf == NULL) { if (!buf) {
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -235,7 +235,7 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state
struct jtag_command *cmd; struct jtag_command *cmd;
cmd = cmd_queue_alloc(sizeof(struct jtag_command)); cmd = cmd_queue_alloc(sizeof(struct jtag_command));
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->type = JTAG_TMS; cmd->type = JTAG_TMS;
@ -350,7 +350,7 @@ void interface_jtag_add_callback4(jtag_callback_t callback,
entry->data2 = data2; entry->data2 = data2;
entry->data3 = data3; entry->data3 = data3;
if (jtag_callback_queue_head == NULL) { if (!jtag_callback_queue_head) {
jtag_callback_queue_head = entry; jtag_callback_queue_head = entry;
jtag_callback_queue_tail = entry; jtag_callback_queue_tail = entry;
} else { } else {

View File

@ -176,7 +176,7 @@ static void ft232r_increase_buf_size(size_t new_buf_size)
if (new_buf_size >= ft232r_buf_size) { if (new_buf_size >= ft232r_buf_size) {
new_buf_size += FT232R_BUF_SIZE_EXTRA; new_buf_size += FT232R_BUF_SIZE_EXTRA;
new_buf_ptr = realloc(ft232r_output, new_buf_size); new_buf_ptr = realloc(ft232r_output, new_buf_size);
if (new_buf_ptr != NULL) { if (new_buf_ptr) {
ft232r_output = new_buf_ptr; ft232r_output = new_buf_ptr;
ft232r_buf_size = new_buf_size; ft232r_buf_size = new_buf_size;
} }
@ -259,7 +259,7 @@ static int ft232r_init(void)
uint16_t apids[] = {ft232r_pid, 0}; uint16_t apids[] = {ft232r_pid, 0};
if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) { if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) {
LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n", 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; return ERROR_JTAG_INIT_FAILED;
} }
@ -310,7 +310,7 @@ static int ft232r_init(void)
} }
ft232r_output = malloc(ft232r_buf_size); ft232r_output = malloc(ft232r_buf_size);
if (ft232r_output == NULL) { if (!ft232r_output) {
LOG_ERROR("Unable to allocate memory for the buffer"); LOG_ERROR("Unable to allocate memory for the buffer");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }

View File

@ -935,7 +935,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
if (CMD_ARGC > 0) { if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[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; return ERROR_COMMAND_SYNTAX_ERROR;
ftdi_jtag_mode = n->value; 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. */ * pointers into the queue which may be invalid after the realloc. */
queued_retval = ftdi_swd_run_queue(); 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)); 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 = q;
swd_cmd_queue_alloced *= 2; swd_cmd_queue_alloced *= 2;
LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced); LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);

View File

@ -294,7 +294,7 @@ static int jlink_execute_queue(void)
int ret; int ret;
struct jtag_command *cmd = jtag_command_queue; struct jtag_command *cmd = jtag_command_queue;
while (cmd != NULL) { while (cmd) {
ret = jlink_execute_command(cmd); ret = jlink_execute_command(cmd);
if (ret != ERROR_OK) if (ret != ERROR_OK)

View File

@ -49,7 +49,7 @@ static int last_ir_num_bits;
static int write_sock(char *buf, size_t len) static int write_sock(char *buf, size_t len)
{ {
if (buf == NULL) { if (!buf) {
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d", LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; 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) static int read_sock(char *buf, size_t len)
{ {
if (buf == NULL) { if (!buf) {
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d", LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -123,7 +123,7 @@ static int jtag_dpi_scan(struct scan_command *cmd)
int ret = ERROR_OK; int ret = ERROR_OK;
num_bits = jtag_build_buffer(cmd, &data_buf); 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, " LOG_ERROR("jtag_build_buffer call failed, data_buf == NULL, "
"file %s, line %d", __FILE__, __LINE__); "file %s, line %d", __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -133,7 +133,7 @@ static int jtag_dpi_scan(struct scan_command *cmd)
if (cmd->ir_scan) { if (cmd->ir_scan) {
free(last_ir_buf); free(last_ir_buf);
last_ir_buf = (uint8_t *)malloc(bytes * sizeof(uint8_t)); 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", LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
ret = ERROR_FAIL; ret = ERROR_FAIL;
@ -181,7 +181,7 @@ static int jtag_dpi_runtest(int cycles)
int num_bits = last_ir_num_bits, bytes; int num_bits = last_ir_num_bits, bytes;
int ret = ERROR_OK; int ret = ERROR_OK;
if (data_buf == NULL) { if (!data_buf) {
LOG_ERROR("%s: NULL 'data_buf' argument, file %s, line %d", LOG_ERROR("%s: NULL 'data_buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -194,7 +194,7 @@ static int jtag_dpi_runtest(int cycles)
bytes = DIV_ROUND_UP(num_bits, 8); bytes = DIV_ROUND_UP(num_bits, 8);
read_scan = (uint8_t *)malloc(bytes * sizeof(uint8_t)); 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", LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -289,9 +289,9 @@ static int jtag_dpi_init(void)
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(server_port); serv_addr.sin_port = htons(server_port);
if (server_address == NULL) { if (!server_address) {
server_address = strdup(SERVER_ADDRESS); server_address = strdup(SERVER_ADDRESS);
if (server_address == NULL) { if (!server_address) {
LOG_ERROR("%s: strdup fail, file %s, line %d", LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -350,9 +350,9 @@ COMMAND_HANDLER(jtag_dpi_set_address)
if (CMD_ARGC > 1) if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
else if (CMD_ARGC == 0) { else if (CMD_ARGC == 0) {
if (server_address == NULL) { if (!server_address) {
server_address = strdup(SERVER_ADDRESS); server_address = strdup(SERVER_ADDRESS);
if (server_address == NULL) { if (!server_address) {
LOG_ERROR("%s: strdup fail, file %s, line %d", LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;
@ -362,7 +362,7 @@ COMMAND_HANDLER(jtag_dpi_set_address)
} else { } else {
free(server_address); free(server_address);
server_address = strdup(CMD_ARGV[0]); server_address = strdup(CMD_ARGV[0]);
if (server_address == NULL) { if (!server_address) {
LOG_ERROR("%s: strdup fail, file %s, line %d", LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__); __func__, __FILE__, __LINE__);
return ERROR_FAIL; return ERROR_FAIL;

View File

@ -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); string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH);
ptr = strtok(loc, "-"); ptr = strtok(loc, "-");
if (ptr == NULL) { if (!ptr) {
LOG_WARNING("no '-' in usb path\n"); LOG_WARNING("no '-' in usb path\n");
goto done; goto done;
} }
@ -61,7 +61,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path,
ptr = strtok(NULL, "."); ptr = strtok(NULL, ".");
/* no more tokens in path */ /* no more tokens in path */
if (ptr == NULL) if (!ptr)
break; break;
/* path mismatch at some step */ /* path mismatch at some step */

View File

@ -158,7 +158,7 @@ static int kitprog_init(void)
int retval; int retval;
kitprog_handle = malloc(sizeof(struct kitprog)); kitprog_handle = malloc(sizeof(struct kitprog));
if (kitprog_handle == NULL) { if (!kitprog_handle) {
LOG_ERROR("Failed to allocate memory"); LOG_ERROR("Failed to allocate memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -208,14 +208,14 @@ static int kitprog_init(void)
/* Allocate packet buffers and queues */ /* Allocate packet buffers and queues */
kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH; kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH;
kitprog_handle->packet_buffer = malloc(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"); LOG_ERROR("Failed to allocate memory for the packet buffer");
return ERROR_FAIL; return ERROR_FAIL;
} }
pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5; pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5;
pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers)); 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"); LOG_ERROR("Failed to allocate memory for the SWD transfer queue");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -256,7 +256,7 @@ static int kitprog_get_usb_serial(void)
/* Allocate memory for the serial number */ /* Allocate memory for the serial number */
kitprog_handle->serial = calloc(retval + 1, sizeof(char)); 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"); LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -285,7 +285,7 @@ static int kitprog_usb_open(void)
/* Convert the ASCII serial number into a (wchar_t *) */ /* Convert the ASCII serial number into a (wchar_t *) */
size_t len = strlen(kitprog_handle->serial); size_t len = strlen(kitprog_handle->serial);
wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t)); 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"); LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -298,7 +298,7 @@ static int kitprog_usb_open(void)
/* Use HID for the KitBridge interface */ /* Use HID for the KitBridge interface */
kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial); kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial);
free(hid_serial); free(hid_serial);
if (kitprog_handle->hid_handle == NULL) { if (!kitprog_handle->hid_handle) {
LOG_ERROR("Failed to open KitBridge (HID) interface"); LOG_ERROR("Failed to open KitBridge (HID) interface");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -314,7 +314,7 @@ static int kitprog_usb_open(void)
static void kitprog_usb_close(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_close(kitprog_handle->hid_handle);
hid_exit(); hid_exit();
} }
@ -855,7 +855,7 @@ COMMAND_HANDLER(kitprog_handle_serial_command)
{ {
if (CMD_ARGC == 1) { if (CMD_ARGC == 1) {
kitprog_serial = strdup(CMD_ARGV[0]); kitprog_serial = strdup(CMD_ARGV[0]);
if (kitprog_serial == NULL) { if (!kitprog_serial) {
LOG_ERROR("Failed to allocate memory for the serial number"); LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -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); char *alternate_serial = adapter_get_alternate_serial(device, dev_desc);
/* check possible failures */ /* check possible failures */
if (alternate_serial == NULL) if (!alternate_serial)
return false; return false;
/* then compare and free the alternate serial */ /* then compare and free the alternate serial */

View File

@ -207,14 +207,14 @@ static int linuxgpiod_reset(int trst, int srst)
LOG_DEBUG("linuxgpiod_reset"); LOG_DEBUG("linuxgpiod_reset");
/* assume active low */ /* assume active low */
if (gpiod_srst != NULL) { if (gpiod_srst) {
retval1 = gpiod_line_set_value(gpiod_srst, srst ? 0 : 1); retval1 = gpiod_line_set_value(gpiod_srst, srst ? 0 : 1);
if (retval1 < 0) if (retval1 < 0)
LOG_WARNING("set srst value failed"); LOG_WARNING("set srst value failed");
} }
/* assume active low */ /* assume active low */
if (gpiod_trst != NULL) { if (gpiod_trst) {
retval2 = gpiod_line_set_value(gpiod_trst, trst ? 0 : 1); retval2 = gpiod_line_set_value(gpiod_trst, trst ? 0 : 1);
if (retval2 < 0) if (retval2 < 0)
LOG_WARNING("set trst value failed"); 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; int retval;
line = gpiod_chip_get_line(gpiod_chip, offset); line = gpiod_chip_get_line(gpiod_chip, offset);
if (line == NULL) { if (!line) {
LOG_ERROR("Error get line %s", label); LOG_ERROR("Error get line %s", label);
return NULL; return NULL;
} }
@ -304,7 +304,7 @@ static struct gpiod_line *helper_get_output_line(const char *label, unsigned int
int retval; int retval;
line = gpiod_chip_get_line(gpiod_chip, offset); line = gpiod_chip_get_line(gpiod_chip, offset);
if (line == NULL) { if (!line) {
LOG_ERROR("Error get line %s", label); LOG_ERROR("Error get line %s", label);
return NULL; return NULL;
} }
@ -325,7 +325,7 @@ static int linuxgpiod_init(void)
bitbang_interface = &linuxgpiod_bitbang; bitbang_interface = &linuxgpiod_bitbang;
gpiod_chip = gpiod_chip_open_by_number(gpiochip); gpiod_chip = gpiod_chip_open_by_number(gpiochip);
if (gpiod_chip == NULL) { if (!gpiod_chip) {
LOG_ERROR("Cannot open LinuxGPIOD gpiochip %d", gpiochip); LOG_ERROR("Cannot open LinuxGPIOD gpiochip %d", gpiochip);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -343,24 +343,24 @@ static int linuxgpiod_init(void)
} }
gpiod_tdo = helper_get_input_line("tdo", tdo_gpio); gpiod_tdo = helper_get_input_line("tdo", tdo_gpio);
if (gpiod_tdo == NULL) if (!gpiod_tdo)
goto out_error; goto out_error;
gpiod_tdi = helper_get_output_line("tdi", tdi_gpio, 0); gpiod_tdi = helper_get_output_line("tdi", tdi_gpio, 0);
if (gpiod_tdi == NULL) if (!gpiod_tdi)
goto out_error; goto out_error;
gpiod_tck = helper_get_output_line("tck", tck_gpio, 0); gpiod_tck = helper_get_output_line("tck", tck_gpio, 0);
if (gpiod_tck == NULL) if (!gpiod_tck)
goto out_error; goto out_error;
gpiod_tms = helper_get_output_line("tms", tms_gpio, 1); gpiod_tms = helper_get_output_line("tms", tms_gpio, 1);
if (gpiod_tms == NULL) if (!gpiod_tms)
goto out_error; goto out_error;
if (is_gpio_valid(trst_gpio)) { if (is_gpio_valid(trst_gpio)) {
gpiod_trst = helper_get_output_line("trst", trst_gpio, 1); gpiod_trst = helper_get_output_line("trst", trst_gpio, 1);
if (gpiod_trst == NULL) if (!gpiod_trst)
goto out_error; goto out_error;
} }
} }
@ -372,23 +372,23 @@ static int linuxgpiod_init(void)
} }
gpiod_swclk = helper_get_output_line("swclk", swclk_gpio, 1); gpiod_swclk = helper_get_output_line("swclk", swclk_gpio, 1);
if (gpiod_swclk == NULL) if (!gpiod_swclk)
goto out_error; goto out_error;
gpiod_swdio = helper_get_output_line("swdio", swdio_gpio, 1); gpiod_swdio = helper_get_output_line("swdio", swdio_gpio, 1);
if (gpiod_swdio == NULL) if (!gpiod_swdio)
goto out_error; goto out_error;
} }
if (is_gpio_valid(srst_gpio)) { if (is_gpio_valid(srst_gpio)) {
gpiod_srst = helper_get_output_line("srst", srst_gpio, 1); gpiod_srst = helper_get_output_line("srst", srst_gpio, 1);
if (gpiod_srst == NULL) if (!gpiod_srst)
goto out_error; goto out_error;
} }
if (is_gpio_valid(led_gpio)) { if (is_gpio_valid(led_gpio)) {
gpiod_led = helper_get_output_line("led", led_gpio, 0); gpiod_led = helper_get_output_line("led", led_gpio, 0);
if (gpiod_led == NULL) if (!gpiod_led)
goto out_error; goto out_error;
} }

View File

@ -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); LOG_DEBUG("device path has %i steps", path_len);
ptr = strtok(loc, "-:"); ptr = strtok(loc, "-:");
if (ptr == NULL) { if (!ptr) {
LOG_DEBUG("no ':' in path"); LOG_DEBUG("no ':' in path");
goto done; goto done;
} }
@ -131,7 +131,7 @@ static bool device_location_equal(struct libusb_device *device, const char *loca
path_step = 0; path_step = 0;
while (path_step < 7) { while (path_step < 7) {
ptr = strtok(NULL, ".,"); ptr = strtok(NULL, ".,");
if (ptr == NULL) { if (!ptr) {
LOG_DEBUG("no more tokens in path at step %i", path_step); LOG_DEBUG("no more tokens in path at step %i", path_step);
break; break;
} }

View File

@ -161,7 +161,7 @@ COMMAND_HANDLER(opendous_handle_opendous_type_command)
return ERROR_OK; return ERROR_OK;
/* only if the cable name wasn't overwritten by cmdline */ /* 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[] ... */ /* REVISIT first verify that it's listed in cables[] ... */
opendous_type = strdup(CMD_ARGV[0]); opendous_type = strdup(CMD_ARGV[0]);
} }
@ -256,7 +256,7 @@ static int opendous_execute_queue(void)
enum scan_type type; enum scan_type type;
uint8_t *buffer; uint8_t *buffer;
while (cmd != NULL) { while (cmd) {
switch (cmd->type) { switch (cmd->type) {
case JTAG_RUNTEST: case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, 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; cur_opendous_probe = opendous_probes;
if (opendous_type == NULL) { if (!opendous_type) {
opendous_type = strdup("opendous"); opendous_type = strdup("opendous");
LOG_WARNING("No opendous_type specified, using default 'opendous'"); LOG_WARNING("No opendous_type specified, using default 'opendous'");
} }

View File

@ -397,7 +397,7 @@ static int openjtag_init_standard(void)
uint8_t latency_timer; uint8_t latency_timer;
/* Open by device description */ /* Open by device description */
if (openjtag_device_desc == NULL) { if (!openjtag_device_desc) {
LOG_WARNING("no openjtag device description specified, " LOG_WARNING("no openjtag device description specified, "
"using default 'Open JTAG Project'"); "using default 'Open JTAG Project'");
openjtag_device_desc = "Open JTAG Project"; openjtag_device_desc = "Open JTAG Project";
@ -475,7 +475,7 @@ static int openjtag_init_cy7c65215(void)
return ERROR_OK; return ERROR_OK;
err: err:
if (usbh != NULL) if (usbh)
jtag_libusb_close(usbh); jtag_libusb_close(usbh);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -803,7 +803,7 @@ static int openjtag_execute_queue(void)
{ {
struct jtag_command *cmd = jtag_command_queue; struct jtag_command *cmd = jtag_command_queue;
while (cmd != NULL) { while (cmd) {
openjtag_execute_command(cmd); openjtag_execute_command(cmd);
cmd = cmd->next; cmd = cmd->next;
} }

View File

@ -272,7 +272,7 @@ static int parport_init(void)
cur_cable = cables; cur_cable = cables;
if (parport_cable == NULL) { if (!parport_cable) {
parport_cable = strdup("wiggler"); parport_cable = strdup("wiggler");
LOG_WARNING("No parport cable specified, using default 'wiggler'"); LOG_WARNING("No parport cable specified, using default 'wiggler'");
} }

View File

@ -534,7 +534,7 @@ static int presto_jtag_init(void)
{ {
if (presto_open(presto_serial) != ERROR_OK) { if (presto_open(presto_serial) != ERROR_OK) {
presto_close(); presto_close();
if (presto_serial != NULL) if (presto_serial)
LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial); LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial);
else else
LOG_ERROR("Cannot open PRESTO"); LOG_ERROR("Cannot open PRESTO");

View File

@ -263,7 +263,7 @@ static int remote_bitbang_init_tcp(void)
freeaddrinfo(result); /* No longer needed */ freeaddrinfo(result); /* No longer needed */
if (rp == NULL) { /* No address succeeded */ if (!rp) { /* No address succeeded */
log_socket_error("Failed to connect"); log_socket_error("Failed to connect");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -273,7 +273,7 @@ static int remote_bitbang_init_tcp(void)
static int remote_bitbang_init_unix(void) static int remote_bitbang_init_unix(void)
{ {
if (remote_bitbang_host == NULL) { if (!remote_bitbang_host) {
LOG_ERROR("host/socket not specified"); LOG_ERROR("host/socket not specified");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -306,7 +306,7 @@ static int remote_bitbang_init(void)
remote_bitbang_recv_buf_end = 0; remote_bitbang_recv_buf_end = 0;
LOG_INFO("Initializing remote_bitbang driver"); LOG_INFO("Initializing remote_bitbang driver");
if (remote_bitbang_port == NULL) if (!remote_bitbang_port)
remote_bitbang_fd = remote_bitbang_init_unix(); remote_bitbang_fd = remote_bitbang_init_unix();
else else
remote_bitbang_fd = remote_bitbang_init_tcp(); remote_bitbang_fd = remote_bitbang_init_tcp();

View File

@ -608,7 +608,7 @@ static inline struct dtc_reply_queue_entry *dtc_queue_enqueue_reply(
struct dtc_reply_queue_entry *rq_entry; struct dtc_reply_queue_entry *rq_entry;
rq_entry = malloc(sizeof(struct dtc_reply_queue_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.type = type;
rq_entry->scan.buffer = buffer; rq_entry->scan.buffer = buffer;
rq_entry->scan.size = size; 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->cmd = cmd;
rq_entry->next = NULL; rq_entry->next = NULL;
if (dtc_queue.rq_head == NULL) if (!dtc_queue.rq_head)
dtc_queue.rq_head = rq_entry; dtc_queue.rq_head = rq_entry;
else else
dtc_queue.rq_tail->next = rq_entry; dtc_queue.rq_tail->next = rq_entry;
@ -665,7 +665,7 @@ static int dtc_queue_run(void)
exit(1); 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 */ /* process the reply, which empties the reply queue and frees its entries */
dtc_p = reply_buffer; dtc_p = reply_buffer;

View File

@ -475,7 +475,7 @@ static unsigned int stlink_usb_block(void *handle)
{ {
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.flags & STLINK_F_HAS_RW8_512BYTES) if (h->version.flags & STLINK_F_HAS_RW8_512BYTES)
return STLINKV3_MAX_RW8; 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; struct stlink_usb_handle_s *h = handle;
int tr, ret; int tr, ret;
assert(handle != NULL); assert(handle);
/* read status */ /* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
size_t n_transfers = 0; size_t n_transfers = 0;
struct jtag_xfer transfers[2]; 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; struct stlink_usb_handle_s *h = handle;
int tr, ret; int tr, ret;
assert(handle != NULL); assert(handle);
ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf, ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf,
cmdsize, STLINK_WRITE_TIMEOUT, &tr); cmdsize, STLINK_WRITE_TIMEOUT, &tr);
@ -742,7 +742,7 @@ static int stlink_usb_xfer_v1_get_sense(void *handle)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 16); 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; int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.stlink == 1) { if (h->version.stlink == 1) {
cmdsize = STLINK_SG_SIZE; 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* send the TCP command */ /* send the TCP command */
int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0); 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 send_size = STLINK_TCP_USB_CMD_SIZE;
int recv_size = STLINK_TCP_SS_SIZE; int recv_size = STLINK_TCP_SS_SIZE;
assert(handle != NULL); assert(handle);
/* prepare the TCP command */ /* prepare the TCP command */
h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD; 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) { if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
switch (h->databuf[0]) { 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE); assert(h->version.flags & STLINK_F_HAS_TRACE);
@ -1141,7 +1141,7 @@ static int stlink_usb_version(void *handle)
char *p; char *p;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 6); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ)) if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ))
return ERROR_COMMAND_NOTFOUND; 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ)) if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;
@ -1405,7 +1405,7 @@ static int stlink_usb_current_mode(void *handle, uint8_t *mode)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2); 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; int rx_size = 0;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* on api V2 we are able the read the latest command /* on api V2 we are able the read the latest command
* status * status
@ -1475,7 +1475,7 @@ static int stlink_usb_mode_leave(void *handle, enum stlink_mode type)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* command with no reply, use a valid endpoint but zero size */ /* command with no reply, use a valid endpoint but zero size */
stlink_usb_init_buffer(handle, h->rx_ep, 0); stlink_usb_init_buffer(handle, h->rx_ep, 0);
@ -1528,7 +1528,7 @@ static int stlink_usb_exit_mode(void *handle)
uint8_t mode; uint8_t mode;
enum stlink_mode emode; enum stlink_mode emode;
assert(handle != NULL); assert(handle);
res = stlink_usb_current_mode(handle, &mode); 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; enum stlink_mode emode;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
res = stlink_usb_exit_mode(handle); res = stlink_usb_exit_mode(handle);
if (res != ERROR_OK) if (res != ERROR_OK)
@ -1867,7 +1867,7 @@ static int stlink_usb_idcode(void *handle, uint32_t *idcode)
int res, offset; int res, offset;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* there is no swim read core id cmd */ /* there is no swim read core id cmd */
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) { 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; struct stlink_usb_handle_s *h = handle;
int res; int res;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 8); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) { if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) {
int res; int res;
@ -1999,7 +1999,7 @@ static enum target_state stlink_usb_state(void *handle)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->reconnect_pending) { if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect"); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_assert_reset(handle, srst); return stlink_swim_assert_reset(handle, srst);
@ -2064,7 +2064,7 @@ static void stlink_usb_trace_disable(void *handle)
int res = ERROR_OK; int res = ERROR_OK;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE); assert(h->version.flags & STLINK_F_HAS_TRACE);
@ -2086,7 +2086,7 @@ static int stlink_usb_trace_enable(void *handle)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.flags & STLINK_F_HAS_TRACE) { if (h->version.flags & STLINK_F_HAS_TRACE) {
stlink_usb_init_buffer(handle, h->rx_ep, 10); 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; struct stlink_usb_handle_s *h = handle;
int retval; int retval;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2); stlink_usb_init_buffer(handle, h->rx_ep, 2);
@ -2147,7 +2147,7 @@ static int stlink_usb_run(void *handle)
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) { if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN); 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; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) { if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) { if (h->version.jtag_api != STLINK_JTAG_API_V1) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr /* 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; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 88); 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; int res;
struct stlink_usb_handle_s *h = handle; 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)) { 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); 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; 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)) { 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); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (h->version.jtag_api == STLINK_JTAG_API_V1) if (h->version.jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK; 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; uint16_t read_len = len;
struct stlink_usb_handle_s *h = handle; 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 */ /* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) { 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; int res;
struct stlink_usb_handle_s *h = handle; 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 */ /* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) { 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; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;
@ -2440,7 +2440,7 @@ static int stlink_usb_write_mem16(void *handle, uint32_t addr, uint16_t len,
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;
@ -2475,7 +2475,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len,
int res; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* data must be a multiple of 4 and word aligned */ /* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) { 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; int res;
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
/* data must be a multiple of 4 and word aligned */ /* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) { if (len % 4 || addr % 4) {
@ -2985,7 +2985,7 @@ static int stlink_tcp_close(void *handle)
/** */ /** */
static int stlink_close(void *handle) static int stlink_close(void *handle)
{ {
if (handle != NULL) { if (handle) {
struct stlink_usb_handle_s *h = handle; struct stlink_usb_handle_s *h = handle;
stlink_usb_close(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 */ /* else (len == 26) => buggy ST-Link */
char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char)); char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char));
if (alternate_serial == NULL) if (!alternate_serial)
return NULL; return NULL;
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2) 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}; char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used; uint8_t stlink_used;
bool stlink_id_matched = false; 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++) { for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */ /* get the stlink info */
@ -3534,8 +3534,8 @@ static int stlink_config_trace(void *handle, bool enabled,
return ERROR_OK; return ERROR_OK;
} }
assert(trace_freq != NULL); assert(trace_freq);
assert(prescaler != NULL); assert(prescaler);
if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) { if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode"); 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT)) if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND; 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT)) if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND; 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; struct stlink_usb_handle_s *h = handle;
int retval; int retval;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG)) if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND; 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; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG)) if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;

View File

@ -122,7 +122,7 @@ static int icdi_send_packet(void *handle, int len)
int result, retry = 0; int result, retry = 0;
int transferred = 0; int transferred = 0;
assert(handle != NULL); assert(handle);
/* check we have a large enough buffer for checksum "#00" */ /* check we have a large enough buffer for checksum "#00" */
if (len + 3 > h->max_packet) { if (len + 3 > h->max_packet) {
@ -253,7 +253,7 @@ static int icdi_get_cmd_result(void *handle)
int offset = 0; int offset = 0;
char ch; char ch;
assert(handle != NULL); assert(handle);
do { do {
ch = h->read_buffer[offset++]; ch = h->read_buffer[offset++];

View File

@ -531,14 +531,14 @@ static int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
payload = calloc(size, sizeof(uint8_t)); payload = calloc(size, sizeof(uint8_t));
if (payload == NULL) { if (!payload) {
LOG_ERROR("Could not allocate OpenULINK command payload: out of memory"); LOG_ERROR("Could not allocate OpenULINK command payload: out of memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
switch (direction) { switch (direction) {
case PAYLOAD_DIRECTION_OUT: case PAYLOAD_DIRECTION_OUT:
if (ulink_cmd->payload_out != NULL) { if (ulink_cmd->payload_out) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command"); LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload); free(payload);
return ERROR_FAIL; return ERROR_FAIL;
@ -548,7 +548,7 @@ static int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
} }
break; break;
case PAYLOAD_DIRECTION_IN: 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"); LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload); free(payload);
return ERROR_FAIL; return ERROR_FAIL;
@ -584,7 +584,7 @@ static int ulink_get_queue_size(struct ulink *device,
struct ulink_cmd *current = device->queue_start; struct ulink_cmd *current = device->queue_start;
int sum = 0; int sum = 0;
while (current != NULL) { while (current) {
switch (direction) { switch (direction) {
case PAYLOAD_DIRECTION_OUT: case PAYLOAD_DIRECTION_OUT:
sum += current->payload_out_size + 1; /* + 1 byte for Command ID */ 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 *current = device->queue_start;
struct ulink_cmd *next = NULL; struct ulink_cmd *next = NULL;
while (current != NULL) { while (current) {
/* Save pointer to next element */ /* Save pointer to next element */
next = current->next; next = current->next;
@ -673,7 +673,7 @@ static int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd)
ulink_clear_queue(device); ulink_clear_queue(device);
} }
if (device->queue_start == NULL) { if (!device->queue_start) {
/* Queue was empty */ /* Queue was empty */
device->commands_in_queue = 1; 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; int ret, i, scan_size_bytes;
uint8_t bits_last_byte; uint8_t bits_last_byte;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
/* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID, /* 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
if (device->delay_clock_tms < 0) 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
if (device->delay_clock_tck < 0) 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_GET_SIGNALS; 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_SET_SIGNALS; 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_SLEEP_US; 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_CONFIGURE_TCK_FREQ; 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_SET_LEDS; 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)); struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret; int ret;
if (cmd == NULL) if (!cmd)
return ERROR_FAIL; return ERROR_FAIL;
cmd->id = CMD_TEST; 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)) { if ((type == SCAN_IN) || (type == SCAN_IO)) {
tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes); tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
if (tdo_buffer_start == NULL) if (!tdo_buffer_start)
return ERROR_FAIL; return ERROR_FAIL;
tdo_buffer = tdo_buffer_start; tdo_buffer = tdo_buffer_start;
@ -1569,9 +1569,9 @@ static int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd)
bytecount -= 58; bytecount -= 58;
/* Update TDI and TDO buffer pointers */ /* Update TDI and TDO buffer pointers */
if (tdi_buffer_start != NULL) if (tdi_buffer_start)
tdi_buffer += 58; tdi_buffer += 58;
if (tdo_buffer_start != NULL) if (tdo_buffer_start)
tdo_buffer += 58; tdo_buffer += 58;
} else if (bytecount == 58) { /* Full scan, no further scans */ } else if (bytecount == 58) { /* Full scan, no further scans */
tms_count_end = last_tms_count; tms_count_end = last_tms_count;
@ -1871,12 +1871,12 @@ static int ulink_post_process_queue(struct ulink *device)
current = device->queue_start; current = device->queue_start;
while (current != NULL) { while (current) {
openocd_cmd = current->cmd_origin; openocd_cmd = current->cmd_origin;
/* Check if a corresponding OpenOCD command is stored for this /* Check if a corresponding OpenOCD command is stored for this
* OpenULINK command */ * OpenULINK command */
if ((current->needs_postprocessing == true) && (openocd_cmd != NULL)) { if ((current->needs_postprocessing == true) && (openocd_cmd)) {
switch (openocd_cmd->type) { switch (openocd_cmd->type) {
case JTAG_SCAN: case JTAG_SCAN:
ret = ulink_post_process_scan(current); ret = ulink_post_process_scan(current);
@ -2122,7 +2122,7 @@ static int ulink_init(void)
uint8_t input_signals, output_signals; uint8_t input_signals, output_signals;
ulink_handle = calloc(1, sizeof(struct ulink)); ulink_handle = calloc(1, sizeof(struct ulink));
if (ulink_handle == NULL) if (!ulink_handle)
return ERROR_FAIL; return ERROR_FAIL;
libusb_init(&ulink_handle->libusb_ctx); libusb_init(&ulink_handle->libusb_ctx);

View File

@ -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; 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]; *((uint8_t *)pending->extra_data) = src[0];
return ERROR_OK; 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; 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]; *((uint8_t *)pending->extra_data) = src[0];
/* mark it processed to ignore other input data */ /* 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 += (request >> 4) & 1;
parity &= 1; parity &= 1;
buff[0] = (request | 0x81 | (parity << 5)) & ~0x40; buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
if (data != NULL) if (data)
SET_LE_U32(&buff[1], *data); SET_LE_U32(&buff[1], *data);
else else
memset(buff + 1, 0, 4); memset(buff + 1, 0, 4);

View File

@ -90,7 +90,7 @@ static RESULT usbtoxxx_validate_current_command_type(void)
{ {
if (type_pre > 0) { if (type_pre > 0) {
/* not the first command */ /* not the first command */
if (NULL == usbtoxxx_buffer) { if (!usbtoxxx_buffer) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
@ -182,8 +182,8 @@ RESULT usbtoxxx_execute_command(void)
struct versaloon_want_pos_t *tmp; struct versaloon_want_pos_t *tmp;
tmp = versaloon_pending[i].pos; tmp = versaloon_pending[i].pos;
while (tmp != NULL) { while (tmp) {
if ((tmp->buff != NULL) && (tmp->size > 0)) { if ((tmp->buff) && (tmp->size > 0)) {
memcpy(tmp->buff, memcpy(tmp->buff,
versaloon_buf + usbtoxxx_buffer_index versaloon_buf + usbtoxxx_buffer_index
+ tmp->offset, + 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)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6))
return ERROR_FAIL; return ERROR_FAIL;
if ((type_pre != type) || (NULL == usbtoxxx_buffer)) { if ((type_pre != type) || (!usbtoxxx_buffer)) {
if (ERROR_OK != usbtoxxx_validate_current_command_type()) { if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; 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); SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp);
} }
if (cmdbuf != NULL) { if (cmdbuf) {
memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen); memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen);
usbtoxxx_current_cmd_index += cmdlen; usbtoxxx_current_cmd_index += cmdlen;
} }

View File

@ -117,7 +117,7 @@ void versaloon_free_want_pos(void)
struct versaloon_want_pos_t *tmp, *free_tmp; struct versaloon_want_pos_t *tmp, *free_tmp;
tmp = versaloon_want_pos; tmp = versaloon_want_pos;
while (tmp != NULL) { while (tmp) {
free_tmp = tmp; free_tmp = tmp;
tmp = tmp->next; tmp = tmp->next;
free(free_tmp); free(free_tmp);
@ -126,7 +126,7 @@ void versaloon_free_want_pos(void)
for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) { for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) {
tmp = versaloon_pending[i].pos; tmp = versaloon_pending[i].pos;
while (tmp != NULL) { while (tmp) {
free_tmp = tmp; free_tmp = tmp;
tmp = tmp->next; tmp = tmp->next;
free(free_tmp); 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; struct versaloon_want_pos_t *new_pos = NULL;
new_pos = malloc(sizeof(*new_pos)); new_pos = malloc(sizeof(*new_pos));
if (NULL == new_pos) { if (!new_pos) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_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->buff = buff;
new_pos->next = NULL; new_pos->next = NULL;
if (NULL == versaloon_want_pos) if (!versaloon_want_pos)
versaloon_want_pos = new_pos; versaloon_want_pos = new_pos;
else { else {
struct versaloon_want_pos_t *tmp = versaloon_want_pos; struct versaloon_want_pos_t *tmp = versaloon_want_pos;
while (tmp->next != NULL) while (tmp->next)
tmp = tmp->next; tmp = tmp->next;
tmp->next = new_pos; tmp->next = new_pos;
} }
@ -199,7 +199,7 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
int transferred; int transferred;
#if PARAM_CHECK #if PARAM_CHECK
if (NULL == versaloon_buf) { if (!versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
@ -217,7 +217,7 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (inlen != NULL) { if (inlen) {
ret = libusb_bulk_transfer(versaloon_usb_device_handle, ret = libusb_bulk_transfer(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_in, versaloon_interface.usb_setting.ep_in,
versaloon_buf, versaloon_interface.usb_setting.buf_size, versaloon_buf, versaloon_interface.usb_setting.buf_size,
@ -242,7 +242,7 @@ static RESULT versaloon_init(void)
/* malloc temporary buffer */ /* malloc temporary buffer */
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size); versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) { if (!versaloon_buf) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
@ -274,13 +274,13 @@ static RESULT versaloon_init(void)
versaloon_buf = NULL; versaloon_buf = NULL;
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size); versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) { if (!versaloon_buf) {
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3); versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
if (NULL == versaloon_cmd_buf) { if (!versaloon_cmd_buf) {
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
@ -294,7 +294,7 @@ static RESULT versaloon_init(void)
static RESULT versaloon_fini(void) static RESULT versaloon_fini(void)
{ {
if (versaloon_usb_device_handle != NULL) { if (versaloon_usb_device_handle) {
usbtoxxx_fini(); usbtoxxx_fini();
versaloon_free_want_pos(); versaloon_free_want_pos();
@ -325,11 +325,11 @@ static RESULT versaloon_get_target_voltage(uint16_t *voltage)
uint16_t inlen; uint16_t inlen;
#if PARAM_CHECK #if PARAM_CHECK
if (NULL == versaloon_buf) { if (!versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
if (NULL == voltage) { if (!voltage) {
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__); LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
return ERRCODE_INVALID_PARAMETER; return ERRCODE_INVALID_PARAMETER;
} }

View File

@ -105,7 +105,7 @@ static int vsllink_execute_queue(void)
" vsllink " " vsllink "
"-------------------------------------"); "-------------------------------------");
while (cmd != NULL) { while (cmd) {
switch (cmd->type) { switch (cmd->type) {
case JTAG_RUNTEST: case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %s", LOG_DEBUG_IO("runtest %i cycles, end in %s",
@ -280,7 +280,7 @@ static int vsllink_quit(void)
static int vsllink_interface_init(void) static int vsllink_interface_init(void)
{ {
vsllink_handle = malloc(sizeof(struct vsllink)); vsllink_handle = malloc(sizeof(struct vsllink));
if (NULL == vsllink_handle) { if (!vsllink_handle) {
LOG_ERROR("unable to allocate memory"); LOG_ERROR("unable to allocate memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -333,7 +333,7 @@ static int vsllink_init(void)
tdi_buffer = malloc(tap_buffer_size); tdi_buffer = malloc(tap_buffer_size);
tdo_buffer = malloc(tap_buffer_size); tdo_buffer = malloc(tap_buffer_size);
tms_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(); vsllink_quit();
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -400,7 +400,7 @@ static bool usb_connect(void)
* 2) didn't find the XDS110, and no devices are currently open * 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 */ /* Free the device list, we're done with it */
libusb_free_device_list(list, 1); libusb_free_device_list(list, 1);
} }
@ -431,12 +431,12 @@ static bool usb_connect(void)
/* On an error, clean up what we can */ /* On an error, clean up what we can */
if (0 != result) { if (0 != result) {
if (NULL != dev) { if (dev) {
/* Release the debug and data interface on the XDS110 */ /* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(dev, xds110.interface); (void)libusb_release_interface(dev, xds110.interface);
libusb_close(dev); libusb_close(dev);
} }
if (NULL != ctx) if (ctx)
libusb_exit(ctx); libusb_exit(ctx);
xds110.ctx = NULL; xds110.ctx = NULL;
xds110.dev = NULL; xds110.dev = NULL;
@ -453,13 +453,13 @@ static bool usb_connect(void)
static void usb_disconnect(void) static void usb_disconnect(void)
{ {
if (NULL != xds110.dev) { if (xds110.dev) {
/* Release the debug and data interface on the XDS110 */ /* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(xds110.dev, xds110.interface); (void)libusb_release_interface(xds110.dev, xds110.interface);
libusb_close(xds110.dev); libusb_close(xds110.dev);
xds110.dev = NULL; xds110.dev = NULL;
} }
if (NULL != xds110.ctx) { if (xds110.ctx) {
libusb_exit(xds110.ctx); libusb_exit(xds110.ctx);
xds110.ctx = NULL; xds110.ctx = NULL;
} }
@ -505,7 +505,7 @@ static bool usb_write(unsigned char *buffer, int size, int *written)
retries++; retries++;
} }
if (NULL != written) if (written)
*written = bytes_written; *written = bytes_written;
return (result == 0 && size == bytes_written) ? true : false; 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 */ /* Abort now if we didn't receive a valid response */
if (!success) { if (!success) {
if (NULL != total_bytes_read) if (total_bytes_read)
*total_bytes_read = 0; *total_bytes_read = 0;
return false; return false;
} }
@ -587,7 +587,7 @@ static bool usb_get_response(uint32_t *total_bytes_read, uint32_t timeout)
if (!success) if (!success)
count = 0; count = 0;
if (NULL != total_bytes_read) if (total_bytes_read)
*total_bytes_read = count; *total_bytes_read = count;
return success; return success;
@ -636,7 +636,7 @@ static bool xds_execute(uint32_t out_length, uint32_t in_length,
int error = 0; int error = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
if (NULL == xds110.dev) if (!xds110.dev)
return false; return false;
while (!done && attempts > 0) { while (!done && attempts > 0) {
@ -714,9 +714,9 @@ static bool xds_version(uint32_t *firmware_id, uint16_t *hardware_id)
DEFAULT_TIMEOUT); DEFAULT_TIMEOUT);
if (success) { if (success) {
if (NULL != firmware_id) if (firmware_id)
*firmware_id = xds110_get_u32(fw_id_pntr); *firmware_id = xds110_get_u32(fw_id_pntr);
if (NULL != hardware_id) if (hardware_id)
*hardware_id = xds110_get_u16(hw_id_pntr); *hardware_id = xds110_get_u16(hw_id_pntr);
} }
@ -863,7 +863,7 @@ static bool cmapi_connect(uint32_t *idcode)
DEFAULT_TIMEOUT); DEFAULT_TIMEOUT);
if (success) { if (success) {
if (NULL != idcode) if (idcode)
*idcode = xds110_get_u32(idcode_pntr); *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); DEFAULT_TIMEOUT);
if (success) { if (success) {
if (NULL != value) if (value)
*value = xds110_get_u32(value_pntr); *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; bool success;
if (NULL == value) if (!value)
return false; return false;
xds110.write_payload[0] = CMAPI_REG_WRITE; xds110.write_payload[0] = CMAPI_REG_WRITE;
@ -1086,7 +1086,7 @@ static bool ocd_pathmove(uint32_t num_states, uint8_t *path)
bool success; bool success;
if (NULL == path) if (!path)
return false; return false;
xds110.write_payload[0] = OCD_PATHMOVE; 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 */ /* Handle result of read attempt */
if (!success) if (!success)
LOG_ERROR("XDS110: failed to read DAP register"); LOG_ERROR("XDS110: failed to read DAP register");
else if (NULL != value) else if (value)
*value = reg_value; *value = reg_value;
if (success && DAP_AP == type) { if (success && DAP_AP == type) {
@ -1867,7 +1867,7 @@ static int xds110_execute_queue(void)
{ {
struct jtag_command *cmd = jtag_command_queue; struct jtag_command *cmd = jtag_command_queue;
while (cmd != NULL) { while (cmd) {
xds110_execute_command(cmd); xds110_execute_command(cmd);
cmd = cmd->next; cmd = cmd->next;
} }

View File

@ -165,7 +165,7 @@ static int hl_interface_speed(int speed)
if (hl_if.layout->api->speed == NULL) if (hl_if.layout->api->speed == NULL)
return ERROR_OK; return ERROR_OK;
if (hl_if.handle == NULL) { if (!hl_if.handle) {
/* pass speed as initial param as interface not open yet */ /* pass speed as initial param as interface not open yet */
hl_if.param.initial_interface_speed = speed; hl_if.param.initial_interface_speed = speed;
return ERROR_OK; return ERROR_OK;

View File

@ -94,7 +94,7 @@ int hl_layout_init(struct hl_interface_s *adapter)
{ {
LOG_DEBUG("hl_layout_init"); LOG_DEBUG("hl_layout_init");
if (adapter->layout == NULL) { if (!adapter->layout) {
LOG_ERROR("no layout specified"); LOG_ERROR("no layout specified");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -62,9 +62,9 @@ struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
{ {
const char *cp = Jim_GetString(o, NULL); const char *cp = Jim_GetString(o, NULL);
struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL; struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
if (NULL == cp) if (!cp)
cp = "(unknown)"; cp = "(unknown)";
if (NULL == t) if (!t)
Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp); Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
return t; return t;
} }
@ -162,7 +162,7 @@ static int jim_command_drscan(Jim_Interp *interp, int argc, Jim_Obj * const *arg
assert(e == JIM_OK); assert(e == JIM_OK);
tap = jtag_tap_by_jim_obj(interp, args[1]); tap = jtag_tap_by_jim_obj(interp, args[1]);
if (tap == NULL) if (!tap)
return JIM_ERR; return JIM_ERR;
num_fields = (argc-2)/2; num_fields = (argc-2)/2;
@ -362,7 +362,7 @@ static int jtag_tap_configure_event(struct jim_getopt_info *goi, struct jtag_tap
if (goi->isconfigure) { if (goi->isconfigure) {
if (!found) if (!found)
jteap = calloc(1, sizeof(*jteap)); jteap = calloc(1, sizeof(*jteap));
else if (NULL != jteap->body) else if (jteap->body)
Jim_DecrRefCount(goi->interp, jteap->body); Jim_DecrRefCount(goi->interp, jteap->body);
jteap->interp = goi->interp; jteap->interp = goi->interp;
@ -769,7 +769,7 @@ int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
struct jtag_tap *t; struct jtag_tap *t;
t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]); t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
if (t == NULL) if (!t)
return JIM_ERR; return JIM_ERR;
if (strcasecmp(cmd_name, "tapisenabled") == 0) { if (strcasecmp(cmd_name, "tapisenabled") == 0) {
@ -811,7 +811,7 @@ int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_Obj *o; Jim_Obj *o;
jim_getopt_obj(&goi, &o); jim_getopt_obj(&goi, &o);
t = jtag_tap_by_jim_obj(goi.interp, o); t = jtag_tap_by_jim_obj(goi.interp, o);
if (t == NULL) if (!t)
return JIM_ERR; return JIM_ERR;
return jtag_tap_configure_cmd(&goi, t); return jtag_tap_configure_cmd(&goi, t);
@ -1122,7 +1122,7 @@ COMMAND_HANDLER(handle_irscan_command)
int retval; int retval;
for (i = 0; i < num_fields; i++) { for (i = 0; i < num_fields; i++) {
tap = jtag_tap_by_string(CMD_ARGV[i*2]); tap = jtag_tap_by_string(CMD_ARGV[i*2]);
if (tap == NULL) { if (!tap) {
free(fields); free(fields);
command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]); command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]);

View File

@ -26,7 +26,7 @@
static int virtex2_set_instr(struct jtag_tap *tap, uint32_t new_instr) static int virtex2_set_instr(struct jtag_tap *tap, uint32_t new_instr)
{ {
if (tap == NULL) if (!tap)
return ERROR_FAIL; return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) { if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
@ -204,7 +204,7 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
tap = jtag_tap_by_string(CMD_ARGV[1]); tap = jtag_tap_by_string(CMD_ARGV[1]);
if (tap == NULL) { if (!tap) {
command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]); command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
return ERROR_OK; return ERROR_OK;
} }

View File

@ -93,7 +93,7 @@ int xilinx_read_bit_file(struct xilinx_bit_file *bit_file, const char *filename)
} }
input_file = fopen(filename, "rb"); input_file = fopen(filename, "rb");
if (input_file == NULL) { if (!input_file) {
LOG_ERROR("couldn't open %s: %s", filename, strerror(errno)); LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));
return ERROR_PLD_FILE_LOAD_FAILED; return ERROR_PLD_FILE_LOAD_FAILED;
} }

View File

@ -160,12 +160,12 @@ static int freertos_update_threads(struct rtos *rtos)
unsigned int tasks_found = 0; unsigned int tasks_found = 0;
const struct freertos_params *param; const struct freertos_params *param;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -1; return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params; param = (const struct freertos_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) { if (!rtos->symbols) {
LOG_ERROR("No symbols for FreeRTOS"); LOG_ERROR("No symbols for FreeRTOS");
return -3; return -3;
} }
@ -403,13 +403,13 @@ static int freertos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
const struct freertos_params *param; const struct freertos_params *param;
int64_t stack_ptr = 0; int64_t stack_ptr = 0;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (thread_id == 0) if (thread_id == 0)
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -1; return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params; param = (const struct freertos_params *) rtos->rtos_specific_params;
@ -494,13 +494,13 @@ static int freertos_get_thread_ascii_info(struct rtos *rtos, threadid_t thread_i
int retval; int retval;
const struct freertos_params *param; const struct freertos_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (thread_id == 0) if (thread_id == 0)
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct freertos_params *) rtos->rtos_specific_params; param = (const struct freertos_params *) rtos->rtos_specific_params;

View File

@ -206,7 +206,7 @@ static const struct rtos_register_stacking *get_stacking_info(const struct rtos
{ {
const struct threadx_params *param = (const struct threadx_params *) rtos->rtos_specific_params; const struct threadx_params *param = (const struct threadx_params *) rtos->rtos_specific_params;
if (param->fn_get_stacking_info != NULL) if (param->fn_get_stacking_info)
return param->fn_get_stacking_info(rtos, stack_ptr); return param->fn_get_stacking_info(rtos, stack_ptr);
return param->stacking_info + 0; return param->stacking_info + 0;
@ -216,12 +216,12 @@ static int is_thread_id_valid(const struct rtos *rtos, int64_t thread_id)
{ {
const struct threadx_params *param; const struct threadx_params *param;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return 0; /* invalid */ return 0; /* invalid */
param = (const struct threadx_params *) rtos->rtos_specific_params; param = (const struct threadx_params *) rtos->rtos_specific_params;
if (param->fn_is_thread_id_valid != NULL) if (param->fn_is_thread_id_valid)
return param->fn_is_thread_id_valid(rtos, thread_id); return param->fn_is_thread_id_valid(rtos, thread_id);
return (thread_id != 0); return (thread_id != 0);
@ -263,15 +263,15 @@ static int threadx_update_threads(struct rtos *rtos)
int thread_list_size = 0; int thread_list_size = 0;
const struct threadx_params *param; const struct threadx_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params; param = (const struct threadx_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) { if (!rtos->symbols) {
LOG_ERROR("No symbols for ThreadX"); LOG_ERROR("No symbols for ThreadX");
return -4; return -4;
} }
@ -437,13 +437,13 @@ static int threadx_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
int retval; int retval;
const struct threadx_params *param; const struct threadx_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (!is_thread_id_valid(rtos, thread_id)) if (!is_thread_id_valid(rtos, thread_id))
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params; param = (const struct threadx_params *) rtos->rtos_specific_params;
@ -469,7 +469,7 @@ static int threadx_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
const struct rtos_register_stacking *stacking_info = const struct rtos_register_stacking *stacking_info =
get_stacking_info(rtos, stack_ptr); get_stacking_info(rtos, stack_ptr);
if (stacking_info == NULL) { if (!stacking_info) {
LOG_ERROR("Unknown stacking info for thread id=0x%" PRIx64, (uint64_t)thread_id); LOG_ERROR("Unknown stacking info for thread id=0x%" PRIx64, (uint64_t)thread_id);
return -6; return -6;
} }
@ -518,18 +518,18 @@ static int threadx_get_thread_detail(struct rtos *rtos,
const struct threadx_params *param; const struct threadx_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (thread_id == 0) if (thread_id == 0)
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params; param = (const struct threadx_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) { if (!rtos->symbols) {
LOG_ERROR("No symbols for ThreadX"); LOG_ERROR("No symbols for ThreadX");
return -3; return -3;
} }

View File

@ -469,8 +469,8 @@ static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
const struct chibios_params *param; const struct chibios_params *param;
uint32_t stack_ptr = 0; uint32_t stack_ptr = 0;
if ((rtos == NULL) || (thread_id == 0) || if ((!rtos) || (thread_id == 0) ||
(rtos->rtos_specific_params == NULL)) (!rtos->rtos_specific_params))
return -1; return -1;
param = (const struct chibios_params *) rtos->rtos_specific_params; param = (const struct chibios_params *) rtos->rtos_specific_params;

View File

@ -102,15 +102,15 @@ static int ecos_update_threads(struct rtos *rtos)
int thread_list_size = 0; int thread_list_size = 0;
const struct ecos_params *param; const struct ecos_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params; param = (const struct ecos_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) { if (!rtos->symbols) {
LOG_ERROR("No symbols for eCos"); LOG_ERROR("No symbols for eCos");
return -4; return -4;
} }
@ -289,13 +289,13 @@ static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
int retval; int retval;
const struct ecos_params *param; const struct ecos_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (thread_id == 0) if (thread_id == 0)
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params; param = (const struct ecos_params *) rtos->rtos_specific_params;

View File

@ -187,13 +187,13 @@ static int embkernel_update_threads(struct rtos *rtos)
int retval; int retval;
const struct embkernel_params *param; const struct embkernel_params *param;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -3; return -3;
if (rtos->symbols == NULL) { if (!rtos->symbols) {
LOG_ERROR("No symbols for embKernel"); LOG_ERROR("No symbols for embKernel");
return -4; return -4;
} }
@ -308,13 +308,13 @@ static int embkernel_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
const struct embkernel_params *param; const struct embkernel_params *param;
int64_t stack_ptr = 0; int64_t stack_ptr = 0;
if (rtos == NULL) if (!rtos)
return -1; return -1;
if (thread_id == 0) if (thread_id == 0)
return -2; return -2;
if (rtos->rtos_specific_params == NULL) if (!rtos->rtos_specific_params)
return -1; return -1;
param = (const struct embkernel_params *) rtos->rtos_specific_params; param = (const struct embkernel_params *) rtos->rtos_specific_params;

View File

@ -97,7 +97,7 @@ static int hwthread_update_threads(struct rtos *rtos)
int64_t current_thread = 0; int64_t current_thread = 0;
enum target_debug_reason current_reason = DBG_REASON_UNDEFINED; enum target_debug_reason current_reason = DBG_REASON_UNDEFINED;
if (rtos == NULL) if (!rtos)
return -1; return -1;
target = rtos->target; target = rtos->target;
@ -215,7 +215,7 @@ static int hwthread_smp_init(struct target *target)
static struct target *hwthread_find_thread(struct target *target, int64_t thread_id) static struct target *hwthread_find_thread(struct target *target, int64_t thread_id)
{ {
/* Find the thread with that thread_id */ /* Find the thread with that thread_id */
if (target == NULL) if (!target)
return NULL; return NULL;
if (target->smp) { if (target->smp) {
for (struct target_list *head = target->head; head != NULL; head = head->next) { for (struct target_list *head = target->head; head != NULL; head = head->next) {
@ -231,13 +231,13 @@ static struct target *hwthread_find_thread(struct target *target, int64_t thread
static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size) struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size)
{ {
if (rtos == NULL) if (!rtos)
return ERROR_FAIL; return ERROR_FAIL;
struct target *target = rtos->target; struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id); struct target *curr = hwthread_find_thread(target, thread_id);
if (curr == NULL) if (!curr)
return ERROR_FAIL; return ERROR_FAIL;
if (!target_was_examined(curr)) if (!target_was_examined(curr))
@ -281,13 +281,13 @@ static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id, static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
uint32_t reg_num, struct rtos_reg *rtos_reg) uint32_t reg_num, struct rtos_reg *rtos_reg)
{ {
if (rtos == NULL) if (!rtos)
return ERROR_FAIL; return ERROR_FAIL;
struct target *target = rtos->target; struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id); struct target *curr = hwthread_find_thread(target, thread_id);
if (curr == NULL) { if (!curr) {
LOG_ERROR("Couldn't find RTOS thread for id %" PRId64 ".", thread_id); LOG_ERROR("Couldn't find RTOS thread for id %" PRId64 ".", thread_id);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -318,13 +318,13 @@ static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value) static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
{ {
if (rtos == NULL) if (!rtos)
return ERROR_FAIL; return ERROR_FAIL;
struct target *target = rtos->target; struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, rtos->current_thread); struct target *curr = hwthread_find_thread(target, rtos->current_thread);
if (curr == NULL) if (!curr)
return ERROR_FAIL; return ERROR_FAIL;
struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true); struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true);
@ -347,7 +347,7 @@ static int hwthread_target_for_threadid(struct connection *connection, int64_t t
struct target *target = get_target_from_connection(connection); struct target *target = get_target_from_connection(connection);
struct target *curr = hwthread_find_thread(target, thread_id); struct target *curr = hwthread_find_thread(target, thread_id);
if (curr == NULL) if (!curr)
return ERROR_FAIL; return ERROR_FAIL;
*p_target = curr; *p_target = curr;

View File

@ -181,7 +181,7 @@ static int linux_os_thread_reg_list(struct rtos *rtos,
found = 1; found = 1;
else else
next = next->next; next = next->next;
} while ((found == 0) && (next != tmp) && (next != NULL)); } while ((found == 0) && (next != tmp) && (next));
if (found == 0) { if (found == 0) {
LOG_ERROR("could not find thread: %" PRIx64, thread_id); LOG_ERROR("could not find thread: %" PRIx64, thread_id);
@ -408,7 +408,7 @@ static int get_current(struct target *target, int create)
struct current_thread *ctt = linux_os->current_threads; struct current_thread *ctt = linux_os->current_threads;
/* invalid current threads content */ /* invalid current threads content */
while (ctt != NULL) { while (ctt) {
ctt->threadid = -1; ctt->threadid = -1;
ctt->TS = 0xdeadbeef; ctt->TS = 0xdeadbeef;
ctt = ctt->next; ctt = ctt->next;
@ -445,10 +445,10 @@ static int get_current(struct target *target, int create)
linux_os->current_threads; linux_os->current_threads;
cpu = head->target->coreid; cpu = head->target->coreid;
while ((ct != NULL) && (ct->core_id != (int32_t) cpu)) while ((ct) && (ct->core_id != (int32_t) cpu))
ct = ct->next; ct = ct->next;
if ((ct != NULL) && (ct->TS == 0xdeadbeef)) if ((ct) && (ct->TS == 0xdeadbeef))
ct->TS = TS; ct->TS = TS;
else else
LOG_ERROR LOG_ERROR
@ -603,13 +603,13 @@ static struct current_thread *add_current_thread(struct current_thread *currents
{ {
ct->next = NULL; ct->next = NULL;
if (currents == NULL) { if (!currents) {
currents = ct; currents = ct;
return currents; return currents;
} else { } else {
struct current_thread *temp = currents; struct current_thread *temp = currents;
while (temp->next != NULL) while (temp->next)
temp = temp->next; temp = temp->next;
temp->next = ct; temp->next = ct;
@ -640,13 +640,13 @@ static struct threads *liste_add_task(struct threads *task_list, struct threads
t->next = NULL; t->next = NULL;
if (*last == NULL) if (*last == NULL)
if (task_list == NULL) { if (!task_list) {
task_list = t; task_list = t;
return task_list; return task_list;
} else { } else {
struct threads *temp = task_list; struct threads *temp = task_list;
while (temp->next != NULL) while (temp->next)
temp = temp->next; temp = temp->next;
temp->next = t; temp->next = t;
@ -668,15 +668,15 @@ static int current_base_addr(struct linux_os *linux_os, uint32_t base_addr)
struct current_thread *ct = linux_os->current_threads; struct current_thread *ct = linux_os->current_threads;
#ifdef PID_CHECK #ifdef PID_CHECK
while ((ct != NULL) && (ct->pid != pid)) while ((ct) && (ct->pid != pid))
#else #else
while ((ct != NULL) && (ct->TS != base_addr)) while ((ct) && (ct->TS != base_addr))
#endif #endif
ct = ct->next; ct = ct->next;
#ifdef PID_CHECK #ifdef PID_CHECK
if ((ct != NULL) && (ct->pid == pid)) if ((ct) && (ct->pid == pid))
#else #else
if ((ct != NULL) && (ct->TS == base_addr)) if ((ct) && (ct->TS == base_addr))
#endif #endif
return 1; return 1;
@ -777,7 +777,7 @@ static int clean_threadlist(struct target *target)
target->rtos->rtos_specific_params; target->rtos->rtos_specific_params;
struct threads *old, *temp = linux_os->thread_list; struct threads *old, *temp = linux_os->thread_list;
while (temp != NULL) { while (temp) {
old = temp; old = temp;
free(temp->context); free(temp->context);
@ -815,10 +815,10 @@ static int insert_into_threadlist(struct target *target, struct threads *t)
t->status = 1; t->status = 1;
t->next = NULL; t->next = NULL;
if (temp == NULL) if (!temp)
linux_os->thread_list = t; linux_os->thread_list = t;
else { else {
while (temp->next != NULL) while (temp->next)
temp = temp->next; temp = temp->next;
t->next = NULL; t->next = NULL;
@ -836,7 +836,7 @@ static void linux_identify_current_threads(struct target *target)
struct current_thread *ct = linux_os->current_threads; struct current_thread *ct = linux_os->current_threads;
struct threads *t = NULL; struct threads *t = NULL;
while ((ct != NULL)) { while ((ct)) {
if (ct->threadid == -1) { if (ct->threadid == -1) {
/* un-identified thread */ /* un-identified thread */
@ -856,7 +856,7 @@ error_handling:
/* search in the list of threads if pid /* search in the list of threads if pid
already present */ already present */
while ((thread_list != NULL) && (found == 0)) { while ((thread_list) && (found == 0)) {
#ifdef PID_CHECK #ifdef PID_CHECK
if (thread_list->pid == t->pid) { if (thread_list->pid == t->pid) {
#else #else
@ -926,7 +926,7 @@ static int linux_task_update(struct target *target, int context)
linux_os->thread_count = 0; linux_os->thread_count = 0;
/*thread_list = thread_list->next; skip init_task*/ /*thread_list = thread_list->next; skip init_task*/
while (thread_list != NULL) { while (thread_list) {
thread_list->status = 0; /*setting all tasks to dead state*/ thread_list->status = 0; /*setting all tasks to dead state*/
free(thread_list->context); free(thread_list->context);
@ -967,7 +967,7 @@ static int linux_task_update(struct target *target, int context)
thread_list = linux_os->thread_list; thread_list = linux_os->thread_list;
while (thread_list != NULL) { while (thread_list) {
#ifdef PID_CHECK #ifdef PID_CHECK
if (t->pid == thread_list->pid) { if (t->pid == thread_list->pid) {
#else #else
@ -1058,7 +1058,7 @@ static int linux_gdb_thread_packet(struct target *target,
tmp_str += sprintf(tmp_str, "m"); tmp_str += sprintf(tmp_str, "m");
struct threads *temp = linux_os->thread_list; struct threads *temp = linux_os->thread_list;
while (temp != NULL) { while (temp) {
tmp_str += sprintf(tmp_str, "%016" PRIx64, temp->threadid); tmp_str += sprintf(tmp_str, "%016" PRIx64, temp->threadid);
temp = temp->next; temp = temp->next;
if (temp) if (temp)
@ -1079,7 +1079,7 @@ static int linux_gdb_thread_update(struct target *target,
target->rtos->rtos_specific_params; target->rtos->rtos_specific_params;
struct threads *temp = linux_os->thread_list; struct threads *temp = linux_os->thread_list;
while (temp != NULL) { while (temp) {
if (temp->threadid == linux_os->preupdtate_threadid_count + 1) { if (temp->threadid == linux_os->preupdtate_threadid_count + 1) {
/*LOG_INFO("FOUND");*/ /*LOG_INFO("FOUND");*/
found = 1; found = 1;
@ -1098,7 +1098,7 @@ static int linux_gdb_thread_update(struct target *target,
temp = temp->next; temp = temp->next;
while (temp != NULL) { while (temp) {
/*LOG_INFO("INTO GDB THREAD UPDATE WHILE");*/ /*LOG_INFO("INTO GDB THREAD UPDATE WHILE");*/
tmp_strr += sprintf(tmp_strr, ","); tmp_strr += sprintf(tmp_strr, ",");
tmp_strr += tmp_strr +=
@ -1128,7 +1128,7 @@ static int linux_thread_extra_info(struct target *target,
/*LOG_INFO("lookup extra info for thread %" SCNx64, threadid);*/ /*LOG_INFO("lookup extra info for thread %" SCNx64, threadid);*/
struct threads *temp = linux_os->thread_list; struct threads *temp = linux_os->thread_list;
while (temp != NULL) { while (temp) {
if (temp->threadid == threadid) { if (temp->threadid == threadid) {
char *pid = " PID: "; char *pid = " PID: ";
char *pid_current = "*PID: "; char *pid_current = "*PID: ";
@ -1176,7 +1176,7 @@ static int linux_gdb_t_packet(struct connection *connection,
struct threads *temp = linux_os->thread_list; struct threads *temp = linux_os->thread_list;
struct threads *prev = NULL; struct threads *prev = NULL;
while (temp != NULL) { while (temp) {
if (temp->threadid == threadid) { if (temp->threadid == threadid) {
if (temp->status != 0) { if (temp->status != 0) {
gdb_put_packet(connection, "OK", 2); gdb_put_packet(connection, "OK", 2);
@ -1205,7 +1205,7 @@ static int linux_gdb_t_packet(struct connection *connection,
retval = linux_task_update(target, 1); retval = linux_task_update(target, 1);
struct threads *temp = linux_os->thread_list; struct threads *temp = linux_os->thread_list;
while (temp != NULL) { while (temp) {
if (temp->threadid == threadid) { if (temp->threadid == threadid) {
if (temp->status == 1) { if (temp->status == 1) {
gdb_put_packet(connection, "OK", 2); gdb_put_packet(connection, "OK", 2);
@ -1231,20 +1231,20 @@ static int linux_gdb_h_packet(struct connection *connection,
struct current_thread *ct = linux_os->current_threads; struct current_thread *ct = linux_os->current_threads;
/* select to display the current thread of the selected target */ /* select to display the current thread of the selected target */
while ((ct != NULL) && (ct->core_id != target->coreid)) while ((ct) && (ct->core_id != target->coreid))
ct = ct->next; ct = ct->next;
int64_t current_gdb_thread_rq; int64_t current_gdb_thread_rq;
if (linux_os->threads_lookup == 1) { if (linux_os->threads_lookup == 1) {
if ((ct != NULL) && (ct->threadid == -1)) { if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads; ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1)) while ((ct) && (ct->threadid == -1))
ct = ct->next; ct = ct->next;
} }
if (ct == NULL) { if (!ct) {
/* no current thread can be identified /* no current thread can be identified
* any way with smp */ * any way with smp */
LOG_INFO("no current thread identified"); LOG_INFO("no current thread identified");
@ -1253,7 +1253,7 @@ static int linux_gdb_h_packet(struct connection *connection,
struct threads t; struct threads t;
ct = linux_os->current_threads; ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1)) { while ((ct) && (ct->threadid == -1)) {
t.base_addr = ct->TS; t.base_addr = ct->TS;
get_name(target, &t); get_name(target, &t);
LOG_INFO("name of unidentified thread %s", LOG_INFO("name of unidentified thread %s",
@ -1321,7 +1321,7 @@ static int linux_thread_packet(struct connection *connection, char const *packet
break; break;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) { } else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
if (linux_os->thread_list == NULL) { if (!linux_os->thread_list) {
retval = linux_gdb_thread_packet(target, retval = linux_gdb_thread_packet(target,
connection, connection,
packet, packet,
@ -1356,17 +1356,17 @@ static int linux_thread_packet(struct connection *connection, char const *packet
if (linux_os->threads_lookup == 1) { if (linux_os->threads_lookup == 1) {
ct = linux_os->current_threads; ct = linux_os->current_threads;
while ((ct != NULL) && (ct->core_id) != target->coreid) while ((ct) && (ct->core_id) != target->coreid)
ct = ct->next; ct = ct->next;
if ((ct != NULL) && (ct->threadid == -1)) { if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads; ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1)) while ((ct) && (ct->threadid == -1))
ct = ct->next; ct = ct->next;
} }
if ((ct != NULL) && (ct->threadid != if ((ct) && (ct->threadid !=
target->rtos->current_threadid) target->rtos->current_threadid)
&& (target->rtos->current_threadid != -1)) && (target->rtos->current_threadid != -1))
LOG_WARNING("WARNING! current GDB thread do not match " LOG_WARNING("WARNING! current GDB thread do not match "
@ -1478,7 +1478,7 @@ static char *linux_ps_command(struct target *target)
tmp += sprintf(tmp, "PID\t\tCPU\t\tASID\t\tNAME\n"); tmp += sprintf(tmp, "PID\t\tCPU\t\tASID\t\tNAME\n");
tmp += sprintf(tmp, "---\t\t---\t\t----\t\t----\n"); tmp += sprintf(tmp, "---\t\t---\t\t----\t\t----\n");
while (temp != NULL) { while (temp) {
if (temp->status) { if (temp->status) {
if (temp->context) if (temp->context)
tmp += tmp +=

View File

@ -318,7 +318,7 @@ static int mqx_update_threads(
rtos->thread_count = task_queue_size; rtos->thread_count = task_queue_size;
rtos->current_thread = 0; rtos->current_thread = 0;
rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail)); rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail));
if (NULL == rtos->thread_details) if (!rtos->thread_details)
return ERROR_FAIL; return ERROR_FAIL;
/* loop over each task and setup thread details, /* loop over each task and setup thread details,

Some files were not shown because too many files have changed in this diff Show More