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)
{
const char *name_index = strrchr(name, '.');
if (NULL == name_index)
if (!name_index)
return 0;
if (name_index[1] < '0' || name_index[1] > '9')
return ~0U;

View File

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

View File

@ -65,7 +65,7 @@ int nand_fileio_start(struct command_invocation *cmd,
duration_start(&state->bench);
if (NULL != filename) {
if (filename) {
int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY);
if (retval != ERROR_OK) {
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)
return retval;
if (NULL == nand->device) {
if (!nand->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
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 one_read;
if (NULL != s->page) {
if (s->page) {
fileio_read(s->fileio, s->page_size, s->page, &one_read);
if (one_read < s->page_size)
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);
ecc += 10;
}
} else if (NULL != s->oob) {
} else if (s->oob) {
fileio_read(s->fileio, s->oob_size, s->oob, &one_read);
if (one_read < s->oob_size)
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;
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");
return ERROR_FAIL;
}

View File

@ -89,7 +89,7 @@ NAND_DEVICE_COMMAND_HANDLER(mxc_nand_device_command)
int hwecc_needed;
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");
return ERROR_FAIL;
}

View File

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

View File

@ -86,7 +86,7 @@ COMMAND_HANDLER(handle_nand_info_command)
if (retval != ERROR_OK)
return retval;
if (NULL == p->device) {
if (!p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
@ -359,10 +359,10 @@ COMMAND_HANDLER(handle_nand_dump_command)
return retval;
}
if (NULL != s.page)
if (s.page)
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);
s.size -= nand->page_size;
@ -391,7 +391,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command)
if (retval != ERROR_OK)
return retval;
if (NULL == p->device) {
if (!p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
@ -527,14 +527,14 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name,
return ERROR_COMMAND_ARGUMENT_INVALID;
}
if (NULL != controller->commands) {
if (controller->commands) {
retval = register_commands(CMD_CTX, NULL,
controller->commands);
if (retval != ERROR_OK)
return retval;
}
c = malloc(sizeof(struct nand_device));
if (c == NULL) {
if (!c) {
LOG_ERROR("End of memory");
return ERROR_FAIL;
}
@ -560,7 +560,7 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name,
return retval;
}
if (controller->usage == NULL)
if (!controller->usage)
LOG_DEBUG("'%s' driver usage field missing", controller->name);
nand_device_add(c);
@ -580,7 +580,7 @@ COMMAND_HANDLER(handle_nand_device_command)
const char *driver_name = CMD_ARGV[0];
struct nand_flash_controller *controller;
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);
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;
if (target == NULL)
if (!target)
return NULL;
chip = all_sam3_chips;
@ -3126,7 +3126,7 @@ static int sam3_get_details(struct sam3_bank_private *private)
else
details++;
}
if (details->name == NULL) {
if (!details->name) {
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* 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])));
if (bank->sectors == NULL) {
if (!bank->sectors) {
LOG_ERROR("No memory!");
return ERROR_FAIL;
}

View File

@ -2318,7 +2318,7 @@ static struct sam4_chip *target2sam4(struct target *target)
{
struct sam4_chip *chip;
if (target == NULL)
if (!target)
return NULL;
chip = all_sam4_chips;
@ -2611,7 +2611,7 @@ static int sam4_get_details(struct sam4_bank_private *private)
else
details++;
}
if (details->name == NULL) {
if (!details->name) {
LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* 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;
private = get_sam4_bank_private(bank);
if (private == NULL)
if (!private)
return ERROR_FAIL;
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])));
if (bank->sectors == NULL) {
if (!bank->sectors) {
LOG_ERROR("No memory!");
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);
const struct samd_family *family = samd_find_family(id);
if (family == NULL)
if (!family)
return NULL;
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);
if (part == NULL) {
if (!part) {
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL;
}
@ -606,7 +606,7 @@ static int samd_get_reservedmask(struct target *target, uint64_t *mask)
}
const struct samd_family *family;
family = samd_find_family(id);
if (family == NULL) {
if (!family) {
LOG_ERROR("Couldn't determine device family");
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);
const struct samd_family *family = samd_find_family(id);
if (family == NULL)
if (!family)
return NULL;
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);
if (part == NULL) {
if (!part) {
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
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);
/* 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 */
command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
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));
/* Check allocation */
if (bluenrgx_info == NULL) {
if (!bluenrgx_info) {
LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL;
}

View File

@ -140,7 +140,7 @@ static int cc26xx_init(struct flash_bank *bank)
return retval;
/* 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);
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
&cc26xx_bank->working_area);
@ -248,7 +248,7 @@ FLASH_BANK_COMMAND_HANDLER(cc26xx_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR;
cc26xx_bank = malloc(sizeof(struct cc26xx_bank));
if (NULL == cc26xx_bank)
if (!cc26xx_bank)
return ERROR_FAIL;
/* Initialize private flash information */
@ -461,7 +461,7 @@ static int cc26xx_probe(struct flash_bank *bank)
num_sectors = max_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors)
if (!bank->sectors)
return ERROR_FAIL;
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;
cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank));
if (NULL == cc3220sf_bank)
if (!cc3220sf_bank)
return ERROR_FAIL;
/* Initialize private flash information */
@ -441,7 +441,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
free(bank->sectors);
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors)
if (!bank->sectors)
return ERROR_FAIL;
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);
pri_ext = malloc(sizeof(struct cfi_intel_pri_ext));
if (pri_ext == NULL) {
if (!pri_ext) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
@ -522,7 +522,7 @@ static int cfi_read_spansion_pri_ext(struct flash_bank *bank)
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) {
if (!pri_ext) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
@ -624,7 +624,7 @@ static int cfi_read_atmel_pri_ext(struct flash_bank *bank)
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) {
if (!pri_ext) {
LOG_ERROR("Out of memory");
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));
if (cfi_info == NULL) {
if (!cfi_info) {
LOG_ERROR("No memory for flash bank info");
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 */
target_code = malloc(target_code_size);
if (target_code == NULL) {
if (!target_code) {
LOG_ERROR("Out of memory");
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 */
target_code = malloc(target_code_size);
if (target_code == NULL) {
if (!target_code) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}

View File

@ -179,7 +179,7 @@ void flash_bank_add(struct flash_bank *bank)
if (flash_banks) {
/* find last flash bank */
struct flash_bank *p = flash_banks;
while (NULL != p->next) {
while (p->next) {
bank_num += 1;
p = p->next;
}
@ -275,7 +275,7 @@ int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
int retval;
bank = get_flash_bank_by_name_noprobe(name);
if (bank != NULL) {
if (bank) {
retval = bank->driver->auto_probe(bank);
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);
int retval;
if (p == NULL)
if (!p)
return ERROR_FAIL;
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;
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);
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);
if (retval != ERROR_OK)
goto done;
if (c == NULL) {
if (!c) {
LOG_WARNING("no flash bank found for address " TARGET_ADDR_FMT, run_address);
section++; /* and skip it */
section_offset = 0;
@ -903,7 +903,7 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
/* allocate buffer */
buffer = malloc(run_size);
if (buffer == NULL) {
if (!buffer) {
LOG_ERROR("Out of memory for flash bank buffer");
retval = ERROR_FAIL;
goto done;
@ -989,7 +989,7 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
goto done;
}
if (written != NULL)
if (written)
*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)
{
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
if (array == NULL)
if (!array)
return NULL;
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];
}
if (efm32_info->family_data == NULL) {
if (!efm32_info->family_data) {
LOG_ERROR("Unknown MCU family %d", efm32_info->part_family);
return ERROR_FAIL;
}
@ -885,7 +885,7 @@ static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
if (new_buffer == NULL) {
if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
@ -1016,7 +1016,7 @@ static int efm32x_protect_check(struct flash_bank *bank)
return ret;
}
assert(NULL != bank->sectors);
assert(bank->sectors);
for (unsigned int i = 0; i < bank->num_sectors; 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;
info = malloc(sizeof(struct faux_flash_bank));
if (info == NULL) {
if (!info) {
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
info->memory = malloc(bank->size);
if (info->memory == NULL) {
if (!info->memory) {
free(info);
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
@ -68,7 +68,7 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
}
info->target = get_target(CMD_ARGV[5]);
if (info->target == NULL) {
if (!info->target) {
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
free(info->memory);
free(info);

View File

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

View File

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

View File

@ -882,9 +882,9 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
k_chip = kinetis_get_chip(target);
if (k_chip == NULL) {
if (!k_chip) {
k_chip = calloc(sizeof(struct kinetis_chip), 1);
if (k_chip == NULL) {
if (!k_chip) {
LOG_ERROR("No memory");
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)
{
struct kinetis_flash_bank *k_bank = bank->driver_priv;
if (k_bank == NULL)
if (!k_bank)
return;
struct kinetis_chip *k_chip = k_bank->k_chip;
if (k_chip == NULL)
if (!k_chip)
return;
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);
if (bank == NULL)
if (!bank)
return ERROR_FAIL;
bank->target = k_chip->target;
@ -1174,7 +1174,7 @@ COMMAND_HANDLER(kinetis_disable_wdog_handler)
struct target *target = get_current_target(CMD_CTX);
struct kinetis_chip *k_chip = kinetis_get_chip(target);
if (k_chip == NULL)
if (!k_chip)
return ERROR_FAIL;
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]);
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);
continue;
}
@ -1538,7 +1538,7 @@ static int kinetis_check_run_mode(struct kinetis_chip *k_chip)
uint8_t pmstat;
struct target *target;
if (k_chip == NULL) {
if (!k_chip) {
LOG_ERROR("Chip not probed.");
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;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
if (new_buffer == NULL) {
if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
@ -2896,7 +2896,7 @@ COMMAND_HANDLER(kinetis_nvm_partition)
}
switch (sz_type) {
case SHOW_INFO:
if (k_chip == NULL) {
if (!k_chip) {
LOG_ERROR("Chip not probed.");
return ERROR_FAIL;
}

View File

@ -945,7 +945,7 @@ COMMAND_HANDLER(kinetis_ke_securing_test)
if (result != ERROR_OK)
return result;
assert(bank != NULL);
assert(bank);
if (target->state != TARGET_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;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
if (new_buffer == NULL) {
if (!new_buffer) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;

View File

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

View File

@ -882,7 +882,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
/* create and fill sectors array */
bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) {
if (!sectors) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
@ -938,7 +938,7 @@ FLASH_BANK_COMMAND_HANDLER(mrvlqspi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR;
mrvlqspi_info = malloc(sizeof(struct mrvlqspi_flash_bank));
if (mrvlqspi_info == NULL) {
if (!mrvlqspi_info) {
LOG_ERROR("not enough memory");
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 */
if (NULL != msp432_bank->working_area)
if (msp432_bank->working_area)
target_free_working_area(target, msp432_bank->working_area);
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
&msp432_bank->working_area);
@ -569,7 +569,7 @@ FLASH_BANK_COMMAND_HANDLER(msp432_flash_bank_command)
/* Create shared private struct for flash banks */
msp432_bank = malloc(sizeof(struct msp432_bank));
if (NULL == msp432_bank)
if (!msp432_bank)
return ERROR_FAIL;
/* Initialize private flash information */
@ -907,7 +907,7 @@ static int msp432_probe(struct flash_bank *bank)
if (num_sectors > 0) {
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors)
if (!bank->sectors)
return ERROR_FAIL;
}
@ -933,7 +933,7 @@ static int msp432_probe(struct flash_bank *bank)
if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
if (NULL == info)
if (!info)
return ERROR_FAIL;
/* 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;
if (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");
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;
assert(nbank != NULL);
assert(nbank);
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_info *chip = nbank->chip;
assert(chip != NULL);
assert(chip);
res = target_read_u32(chip->target, NRF51_FICR_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_info *chip = nbank->chip;
assert(chip != NULL);
assert(chip);
static uint32_t nrf5_bprot_offsets[4] = { 0x600, 0x604, 0x610, 0x614 };
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_info *chip = nbank->chip;
assert(chip != NULL);
assert(chip);
if (chip->features & NRF5_FEATURE_BPROT)
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_info *chip = nbank->chip;
if (chip == NULL)
if (!chip)
return;
chip->refcount--;
@ -1197,7 +1197,7 @@ FLASH_BANK_COMMAND_HANDLER(nrf5_flash_bank_command)
nbank = &chip->bank[1];
break;
}
assert(nbank != NULL);
assert(nbank);
chip->refcount++;
nbank->chip = chip;
@ -1218,7 +1218,7 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
if (res != ERROR_OK)
return res;
assert(bank != NULL);
assert(bank);
struct nrf5_info *chip;
@ -1265,7 +1265,7 @@ COMMAND_HANDLER(nrf5_handle_info_command)
if (res != ERROR_OK)
return res;
assert(bank != NULL);
assert(bank);
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 */
struct armv7m_common *armv7m = target_to_armv7m(target);
if (armv7m == NULL) {
if (!armv7m) {
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
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;
if (row_offset && (count >= (row_size / 4))) {
new_buffer = malloc(buffer_size);
if (new_buffer == NULL) {
if (!new_buffer) {
LOG_ERROR("Out of memory");
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);
struct armv7m_common *armv7m = target_to_armv7m(target);
if (armv7m == NULL) {
if (!armv7m) {
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
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;
sysrq_buffer = malloc(param_sz + prot_sz);
if (sysrq_buffer == NULL) {
if (!sysrq_buffer) {
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
@ -658,7 +658,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer,
return retval;
sysrq_buffer = malloc(param_sz + psoc4_info->row_size);
if (sysrq_buffer == NULL) {
if (!sysrq_buffer) {
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
@ -833,7 +833,7 @@ static int psoc4_probe(struct flash_bank *bank)
bank->size = num_rows * row_size;
bank->num_sectors = num_rows;
bank->sectors = alloc_block_array(0, row_size, num_rows);
if (bank->sectors == NULL)
if (!bank->sectors)
return ERROR_FAIL;
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;
block_array = malloc(num_sectors * sizeof(struct target_memory_check_block));
if (block_array == NULL)
if (!block_array)
return ERROR_FAIL;
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;
LOG_DEBUG("parameter headers: %d", nph);
pheaders = malloc(sizeof(struct sfdp_phdr) * nph);
if (pheaders == NULL) {
if (!pheaders) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
@ -119,7 +119,7 @@ int spi_sfdp(struct flash_bank *bank, struct flash_device *dev,
/* retrieve parameter table */
ptable = malloc(words << 2);
if (ptable == NULL) {
if (!ptable) {
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;

View File

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

View File

@ -561,7 +561,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
* discrete accesses. */
if (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");
return ERROR_FAIL;
}
@ -1179,7 +1179,7 @@ static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *c
return ERROR_FAIL;
}
if (rev_str != NULL)
if (rev_str)
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
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;
}
if (rev_str != NULL)
if (rev_str)
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
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->num_sectors);
if (bank->sectors == NULL) {
if (!bank->sectors) {
LOG_ERROR("failed to allocate bank sectors");
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->num_prot_blocks);
if (bank->prot_blocks == NULL) {
if (!bank->prot_blocks) {
LOG_ERROR("failed to allocate bank prot_block");
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)
rev_str = info->revs[i].str;
if (rev_str != NULL) {
if (rev_str) {
command_print_sameline(cmd, "%s - Rev: %s",
stm32x_info->part_info->device_str, rev_str);
} 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->num_sectors = num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (bank->sectors == NULL) {
if (!bank->sectors) {
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}

View File

@ -290,7 +290,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32lx_flash_bank_command)
stm32lx_info = calloc(1, sizeof(*stm32lx_info));
/* Check allocation */
if (stm32lx_info == NULL) {
if (!stm32lx_info) {
LOG_ERROR("failed to allocate bank structure");
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);
if (armv7m == NULL) {
if (!armv7m) {
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
@ -842,7 +842,7 @@ static int stm32lx_probe(struct flash_bank *bank)
bank->base = base_address;
bank->num_sectors = 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");
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)
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);
} else {
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);
stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank));
if (stmqspi_info == NULL) {
if (!stmqspi_info) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
@ -754,7 +754,7 @@ COMMAND_HANDLER(stmqspi_handle_set)
bank->num_sectors =
stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) {
if (!sectors) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
@ -2358,7 +2358,7 @@ static int stmqspi_probe(struct flash_bank *bank)
/* create and fill sectors array */
bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) {
if (!sectors) {
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;

View File

@ -144,7 +144,7 @@ FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR;
stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
if (stmsmi_info == NULL) {
if (!stmsmi_info) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
@ -600,7 +600,7 @@ static int stmsmi_probe(struct flash_bank *bank)
bank->num_sectors =
stmsmi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (sectors == NULL) {
if (!sectors) {
LOG_ERROR("not enough memory");
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)
{
if (tap == NULL)
if (!tap)
return ERROR_TARGET_INVALID;
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 */
tap0 = str9xpec_info->tap;
if (tap0 == NULL) {
if (!tap0) {
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
return ERROR_FAIL;
}
tap1 = tap0->next_tap;
if (tap1 == NULL) {
if (!tap1) {
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
return ERROR_FAIL;
}
tap2 = tap1->next_tap;
if (tap2 == NULL) {
if (!tap2) {
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
return ERROR_FAIL;
@ -1089,7 +1089,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap;
if (tap == NULL)
if (!tap)
return ERROR_FAIL;
/* exit turbo mode via RESET */

View File

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

View File

@ -572,7 +572,7 @@ FLASH_BANK_COMMAND_HANDLER(xcf_flash_bank_command)
struct xcf_priv *priv;
priv = malloc(sizeof(struct xcf_priv));
if (priv == NULL) {
if (!priv) {
LOG_ERROR("no memory for flash bank info");
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));
if (bank->sectors == NULL) {
if (!bank->sectors) {
LOG_ERROR("No memory for sector table");
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);
else
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)
{
if (NULL == state)
if (!state)
return;
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)
{
int *return_retval = Jim_GetAssocData(interp, "retval");
if (return_retval != NULL)
if (return_retval)
*return_retval = 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)
{
char **words = malloc(argc * sizeof(char *));
if (NULL == words)
if (!words)
return NULL;
unsigned i;
@ -234,7 +234,7 @@ struct command_context *current_command_context(Jim_Interp *interp)
{
/* grab the command context from the associated data */
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
* happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script.
@ -285,7 +285,7 @@ static struct command *command_new(struct command_context *cmd_ctx,
full_name);
struct command *c = calloc(1, sizeof(struct command));
if (NULL == c)
if (!c)
return NULL;
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;
struct command *c = NULL;
if (NULL != cr->name) {
if (cr->name) {
c = register_command(cmd_ctx, cmd_prefix, cr);
if (NULL == c) {
if (!c) {
retval = ERROR_FAIL;
break;
}
c->jim_handler_data = data;
c->jim_override_target = override_target;
}
if (NULL != cr->chain) {
if (cr->chain) {
if (cr->name) {
if (cmd_prefix) {
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_start(ap, format);
string = alloc_vprintf(format, ap);
if (string != NULL) {
if (string) {
retval = command_run_line(context, 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)
{
if (NULL == cmd_ctx)
if (!cmd_ctx)
return;
free(cmd_ctx);
@ -709,7 +709,7 @@ static int jim_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file);
if (full_path == NULL)
if (!full_path)
return JIM_ERR;
Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(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
* stuff for this command. */
bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
((c->usage != NULL) && (strstr(c->usage, cmd_match) != NULL)) ||
((c->help != NULL) && (strstr(c->help, cmd_match) != NULL));
((c->usage) && (strstr(c->usage, cmd_match) != NULL)) ||
((c->help) && (strstr(c->help, cmd_match) != NULL));
if (is_match) {
if (c->usage && strlen(c->usage) > 0) {
@ -870,7 +870,7 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
} else
msg = alloc_printf("%s", c->help ? c->help : "");
if (NULL != msg) {
if (msg) {
command_help_show_wrap(msg, n + 3, n + 3);
free(msg);
} else
@ -899,7 +899,7 @@ COMMAND_HANDLER(handle_help_command)
}
}
if (cmd_match == NULL) {
if (!cmd_match) {
LOG_ERROR("unable to build search string");
return -ENOMEM;
}
@ -1286,7 +1286,7 @@ struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp
INIT_LIST_HEAD(context->help_list);
/* Create a jim interpreter if we were not handed one */
if (interp == NULL) {
if (!interp) {
/* Create an interpreter */
interp = Jim_CreateInterp();
/* 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);
else {
char *full_path = find_file(file);
if (full_path == NULL)
if (!full_path)
return NULL;
FILE *fp = NULL;
fp = fopen(full_path, mode);
@ -150,12 +150,12 @@ char *get_home_dir(const char *append_path)
{
char *home = getenv("HOME");
if (home == NULL) {
if (!home) {
#ifdef _WIN32
home = getenv("USERPROFILE");
if (home == NULL) {
if (!home) {
char homepath[MAX_PATH];
char *drive = getenv("HOMEDRIVE");
@ -173,7 +173,7 @@ char *get_home_dir(const char *append_path)
#endif
}
if (home == NULL)
if (!home)
return home;
char *home_path;

View File

@ -199,7 +199,7 @@ int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
}
if (puthere)
*puthere = o;
if (o != NULL)
if (o)
return JIM_OK;
else
return JIM_ERR;
@ -227,7 +227,7 @@ int jim_getopt_double(struct jim_getopt_info *goi, double *puthere)
Jim_Obj *o;
double _safe;
if (puthere == NULL)
if (!puthere)
puthere = &_safe;
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_wide _safe;
if (puthere == NULL)
if (!puthere)
puthere = &_safe;
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;
int e;
if (puthere == NULL)
if (!puthere)
puthere = &_safe;
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;
int e;
if (puthere == NULL)
if (!puthere)
puthere = &_safe;
e = jim_getopt_obj(goi, &o);
if (e == JIM_OK)

View File

@ -108,7 +108,7 @@ static void log_puts(enum log_levels level,
}
f = strrchr(file, '/');
if (f != NULL)
if (f)
file = f + 1;
if (strlen(string) > 0) {
@ -163,7 +163,7 @@ void log_printf(enum log_levels level,
va_start(ap, format);
string = alloc_vprintf(format, ap);
if (string != NULL) {
if (string) {
log_puts(level, file, line, function, string);
free(string);
}
@ -240,7 +240,7 @@ COMMAND_HANDLER(handle_log_output_command)
}
if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w");
if (file == NULL) {
if (!file) {
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
return ERROR_FAIL;
}
@ -287,7 +287,7 @@ void log_init(void)
/* set defaults for daemon configuration,
* if not set by cmdline or cfgfile */
char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
if (NULL != debug_env) {
if (debug_env) {
int value;
int retval = parse_int(debug_env, &value);
if (retval == ERROR_OK &&
@ -296,7 +296,7 @@ void log_init(void)
debug_level = value;
}
if (log_output == NULL)
if (!log_output)
log_output = stderr;
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
*check this */
cb = malloc(sizeof(struct log_callback));
if (cb == NULL)
if (!cb)
return ERROR_BUF_TOO_SMALL;
/* 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
* now reserve the extra byte. */
string = malloc(len + 2);
if (string == NULL)
if (!string)
return NULL;
/* do the real work */

View File

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

View File

@ -33,7 +33,7 @@
void *clear_malloc(size_t size)
{
void *t = malloc(size);
if (t != NULL)
if (t)
memset(t, 0x00, size);
return t;
}
@ -41,7 +41,7 @@ void *clear_malloc(size_t size)
void *fill_malloc(size_t size)
{
void *t = malloc(size);
if (t != NULL) {
if (t) {
/* We want to initialize memory to some known bad state.
* 0 and 0xff yields 0 and -1 as integers, which often
* 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);
char *new = malloc(len + 1);
if (new == NULL)
if (!new)
return NULL;
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))
/* calculate how long we need to wait in milliseconds */
if (tv == NULL)
if (!tv)
ms_total = INFINITE;
else {
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;
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");
return JIM_ERR;
}

View File

@ -2215,24 +2215,24 @@ static int aice_execute_custom_script(const char *script)
bool set_op;
script_fd = fopen(script, "r");
if (script_fd == NULL) {
if (!script_fd) {
return ERROR_FAIL;
} else {
while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
/* execute operations */
set_op = false;
op_str = strstr(line_buffer, "set");
if (op_str != NULL) {
if (op_str) {
set_op = true;
goto get_reset_type;
}
op_str = strstr(line_buffer, "clear");
if (op_str == NULL)
if (!op_str)
continue;
get_reset_type:
reset_str = strstr(op_str, "srst");
if (reset_str != NULL) {
if (reset_str) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST;
else
@ -2240,7 +2240,7 @@ get_reset_type:
goto get_delay;
}
reset_str = strstr(op_str, "dbgi");
if (reset_str != NULL) {
if (reset_str) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI;
else
@ -2248,7 +2248,7 @@ get_reset_type:
goto get_delay;
}
reset_str = strstr(op_str, "trst");
if (reset_str != NULL) {
if (reset_str) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST;
else
@ -2732,7 +2732,7 @@ static int aice_usb_reset(void)
return ERROR_FAIL;
/* issue TRST */
if (custom_trst_script == NULL) {
if (!custom_trst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
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. */
aice_restore_edm_registers(coreid);
if (custom_srst_script == NULL) {
if (!custom_srst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK)
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));
/* issue restart */
if (custom_restart_script == NULL) {
if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
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);
/* issue restart again */
if (custom_restart_script == NULL) {
if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL;
@ -3721,7 +3721,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
/* init strtok() */
command_str = strtok(command_sequence, ";");
if (command_str == NULL)
if (!command_str)
return ERROR_OK;
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_1 = strstr(command_str, "gen_port1");
if (reg_name_0 != NULL) {
if (reg_name_0) {
data_value = strtoul(reg_name_0 + 9, NULL, 0);
if (aice_write_misc(coreid,
NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK)
return ERROR_FAIL;
} else if (reg_name_1 != NULL) {
} else if (reg_name_1) {
data_value = strtoul(reg_name_1 + 9, NULL, 0);
if (aice_write_misc(coreid,
@ -3763,7 +3763,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
/* update command_str */
command_str = strtok(NULL, ";");
} while (command_str != NULL);
} while (command_str);
return ERROR_OK;
}

View File

@ -66,7 +66,7 @@ void jtag_queue_command(struct jtag_command *cmd)
cmd->next = NULL;
struct jtag_command **last_cmd = next_command_pointer;
assert(NULL != last_cmd);
assert(last_cmd);
assert(NULL == *last_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)
{
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;
if (callback == NULL)
if (!callback)
return ERROR_COMMAND_SYNTAX_ERROR;
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;
if (callback == NULL)
if (!callback)
return ERROR_COMMAND_SYNTAX_ERROR;
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,
tap_state_t state)
{
assert(out_bits != NULL);
assert(out_bits);
assert(state != TAP_RESET);
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,
tap_state_t state)
{
assert(out_bits != NULL);
assert(out_bits);
assert(state != TAP_RESET);
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)
{
assert(field->in_value != NULL);
assert(field->in_value);
if (value == NULL) {
if (!value) {
/* no checking to do */
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)
{
if (NULL == jtag) {
if (!jtag) {
LOG_ERROR("No JTAG interface configured yet. "
"Issue 'init' command in startup scripts "
"before communicating with targets.");
@ -1230,7 +1230,7 @@ static int jtag_examine_chain(void)
max_taps++;
uint8_t *idcode_buffer = calloc(4, max_taps);
if (idcode_buffer == NULL)
if (!idcode_buffer)
return ERROR_JTAG_INIT_FAILED;
/* 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);
/* No predefined TAP? Auto-probe. */
if (tap == NULL) {
if (!tap) {
/* Is there another TAP? */
if (jtag_idcode_is_final(idcode))
break;
@ -1355,7 +1355,7 @@ static int jtag_validate_ircapture(void)
total_ir_length += 2;
ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8));
if (ir_test == NULL)
if (!ir_test)
return ERROR_FAIL;
/* after this scan, all TAPs will capture BYPASS instructions */
@ -1377,7 +1377,7 @@ static int jtag_validate_ircapture(void)
for (;; ) {
tap = jtag_tap_next_enabled(tap);
if (tap == NULL)
if (!tap)
break;
/* 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;
jtag = adapter_driver;
if (jtag->speed == NULL) {
if (!jtag->speed) {
LOG_INFO("This adapter doesn't support configurable speed");
return ERROR_OK;
}
@ -1574,7 +1574,7 @@ int jtag_init_inner(struct command_context *cmd_ctx)
LOG_DEBUG("Init JTAG chain");
tap = jtag_tap_next_enabled(NULL);
if (tap == NULL) {
if (!tap) {
/* Once JTAG itself is properly set up, and the scan chain
* 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)
{
if (jtag == NULL) {
if (!jtag) {
/* TODO: as the jtag interface is not valid all
* we can do at the moment is exit OpenOCD */
LOG_ERROR("No Valid JTAG Interface Configured.");

View File

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

View File

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

View File

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

View File

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

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));
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
if (dap->bdata == NULL) {
if (!dap->bdata) {
LOG_ERROR("unable to allocate memory");
libusb_release_interface(dev_handle, interface_num);
libusb_close(dev_handle);
@ -370,7 +370,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
dap->bdata->interface = interface_num;
dap->packet_buffer = malloc(dap->packet_buffer_size);
if (dap->packet_buffer == NULL) {
if (!dap->packet_buffer) {
LOG_ERROR("unable to allocate memory");
cmsis_dap_usb_close(dap);
return ERROR_FAIL;
@ -446,7 +446,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
{
uint8_t *buf = malloc(pkt_sz);
if (buf == NULL) {
if (!buf) {
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
}

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

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;
cmd = cmd_queue_alloc(sizeof(struct jtag_command));
if (cmd == NULL)
if (!cmd)
return ERROR_FAIL;
cmd->type = JTAG_TMS;
@ -350,7 +350,7 @@ void interface_jtag_add_callback4(jtag_callback_t callback,
entry->data2 = data2;
entry->data3 = data3;
if (jtag_callback_queue_head == NULL) {
if (!jtag_callback_queue_head) {
jtag_callback_queue_head = entry;
jtag_callback_queue_tail = entry;
} else {

View File

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

View File

@ -935,7 +935,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
if (n->name == NULL)
if (!n->name)
return ERROR_COMMAND_SYNTAX_ERROR;
ftdi_jtag_mode = n->value;
@ -1168,7 +1168,7 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32
* pointers into the queue which may be invalid after the realloc. */
queued_retval = ftdi_swd_run_queue();
struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
if (q != NULL) {
if (q) {
swd_cmd_queue = q;
swd_cmd_queue_alloced *= 2;
LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);

View File

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

View File

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

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

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -475,7 +475,7 @@ static unsigned int stlink_usb_block(void *handle)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.flags & STLINK_F_HAS_RW8_512BYTES)
return STLINKV3_MAX_RW8;
@ -636,7 +636,7 @@ static int stlink_usb_xfer_v1_get_status(void *handle)
struct stlink_usb_handle_s *h = handle;
int tr, ret;
assert(handle != NULL);
assert(handle);
/* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE);
@ -670,7 +670,7 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
size_t n_transfers = 0;
struct jtag_xfer transfers[2];
@ -709,7 +709,7 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int
struct stlink_usb_handle_s *h = handle;
int tr, ret;
assert(handle != NULL);
assert(handle);
ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf,
cmdsize, STLINK_WRITE_TIMEOUT, &tr);
@ -742,7 +742,7 @@ static int stlink_usb_xfer_v1_get_sense(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 16);
@ -790,7 +790,7 @@ static int stlink_usb_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.stlink == 1) {
cmdsize = STLINK_SG_SIZE;
@ -823,7 +823,7 @@ static int stlink_tcp_send_cmd(void *handle, int send_size, int recv_size, bool
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* send the TCP command */
int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0);
@ -868,7 +868,7 @@ static int stlink_tcp_xfer_noerrcheck(void *handle, const uint8_t *buf, int size
int send_size = STLINK_TCP_USB_CMD_SIZE;
int recv_size = STLINK_TCP_SS_SIZE;
assert(handle != NULL);
assert(handle);
/* prepare the TCP command */
h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD;
@ -937,7 +937,7 @@ static int stlink_usb_error_check(void *handle)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
switch (h->databuf[0]) {
@ -1076,7 +1076,7 @@ static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE);
@ -1141,7 +1141,7 @@ static int stlink_usb_version(void *handle)
char *p;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 6);
@ -1355,7 +1355,7 @@ static int stlink_usb_set_swdclk(void *handle, uint16_t clk_divisor)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
@ -1379,7 +1379,7 @@ static int stlink_usb_set_jtagclk(void *handle, uint16_t clk_divisor)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
@ -1405,7 +1405,7 @@ static int stlink_usb_current_mode(void *handle, uint8_t *mode)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
@ -1427,7 +1427,7 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type)
int rx_size = 0;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* on api V2 we are able the read the latest command
* status
@ -1475,7 +1475,7 @@ static int stlink_usb_mode_leave(void *handle, enum stlink_mode type)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* command with no reply, use a valid endpoint but zero size */
stlink_usb_init_buffer(handle, h->rx_ep, 0);
@ -1528,7 +1528,7 @@ static int stlink_usb_exit_mode(void *handle)
uint8_t mode;
enum stlink_mode emode;
assert(handle != NULL);
assert(handle);
res = stlink_usb_current_mode(handle, &mode);
@ -1569,7 +1569,7 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init
enum stlink_mode emode;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
res = stlink_usb_exit_mode(handle);
if (res != ERROR_OK)
@ -1867,7 +1867,7 @@ static int stlink_usb_idcode(void *handle, uint32_t *idcode)
int res, offset;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* there is no swim read core id cmd */
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
@ -1905,7 +1905,7 @@ static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *v
struct stlink_usb_handle_s *h = handle;
int res;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 8);
@ -1926,7 +1926,7 @@ static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
@ -1948,7 +1948,7 @@ static int stlink_usb_trace_read(void *handle, uint8_t *buf, size_t *size)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) {
int res;
@ -1999,7 +1999,7 @@ static enum target_state stlink_usb_state(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect");
@ -2041,7 +2041,7 @@ static int stlink_usb_assert_srst(void *handle, int srst)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_assert_reset(handle, srst);
@ -2064,7 +2064,7 @@ static void stlink_usb_trace_disable(void *handle)
int res = ERROR_OK;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
assert(h->version.flags & STLINK_F_HAS_TRACE);
@ -2086,7 +2086,7 @@ static int stlink_usb_trace_enable(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.flags & STLINK_F_HAS_TRACE) {
stlink_usb_init_buffer(handle, h->rx_ep, 10);
@ -2118,7 +2118,7 @@ static int stlink_usb_reset(void *handle)
struct stlink_usb_handle_s *h = handle;
int retval;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
@ -2147,7 +2147,7 @@ static int stlink_usb_run(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
@ -2169,7 +2169,7 @@ static int stlink_usb_halt(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
@ -2190,7 +2190,7 @@ static int stlink_usb_step(void *handle)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr
@ -2214,7 +2214,7 @@ static int stlink_usb_read_regs(void *handle)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 88);
@ -2239,7 +2239,7 @@ static int stlink_usb_read_reg(void *handle, unsigned int regsel, uint32_t *val)
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
res = stlink_usb_write_debug_reg(h, DCB_DCRSR, regsel & 0x7f);
@ -2279,7 +2279,7 @@ static int stlink_usb_write_reg(void *handle, unsigned int regsel, uint32_t val)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
int res = stlink_usb_write_debug_reg(h, DCB_DCRDR, val);
@ -2308,7 +2308,7 @@ static int stlink_usb_get_rw_status(void *handle)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (h->version.jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK;
@ -2333,7 +2333,7 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len,
uint16_t read_len = len;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
@ -2371,7 +2371,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len,
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
@ -2403,7 +2403,7 @@ static int stlink_usb_read_mem16(void *handle, uint32_t addr, uint16_t len,
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
@ -2440,7 +2440,7 @@ static int stlink_usb_write_mem16(void *handle, uint32_t addr, uint16_t len,
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
@ -2475,7 +2475,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len,
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
@ -2509,7 +2509,7 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len,
int res;
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
@ -2985,7 +2985,7 @@ static int stlink_tcp_close(void *handle)
/** */
static int stlink_close(void *handle)
{
if (handle != NULL) {
if (handle) {
struct stlink_usb_handle_s *h = handle;
stlink_usb_close(handle);
@ -3064,7 +3064,7 @@ static char *stlink_usb_get_alternate_serial(struct libusb_device_handle *device
/* else (len == 26) => buggy ST-Link */
char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char));
if (alternate_serial == NULL)
if (!alternate_serial)
return NULL;
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
@ -3307,7 +3307,7 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param)
char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used;
bool stlink_id_matched = false;
bool stlink_serial_matched = (param->serial == NULL);
bool stlink_serial_matched = (!param->serial);
for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */
@ -3534,8 +3534,8 @@ static int stlink_config_trace(void *handle, bool enabled,
return ERROR_OK;
}
assert(trace_freq != NULL);
assert(prescaler != NULL);
assert(trace_freq);
assert(prescaler);
if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
@ -3585,7 +3585,7 @@ static int stlink_usb_init_access_port(void *handle, unsigned char ap_num)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
@ -3604,7 +3604,7 @@ static int stlink_usb_close_access_port(void *handle, unsigned char ap_num)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
@ -3630,7 +3630,7 @@ static int stlink_read_dap_register(void *handle, unsigned short dap_port,
struct stlink_usb_handle_s *h = handle;
int retval;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
@ -3653,7 +3653,7 @@ static int stlink_write_dap_register(void *handle, unsigned short dap_port,
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
assert(handle);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -94,7 +94,7 @@ int hl_layout_init(struct hl_interface_s *adapter)
{
LOG_DEBUG("hl_layout_init");
if (adapter->layout == NULL) {
if (!adapter->layout) {
LOG_ERROR("no layout specified");
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);
struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
if (NULL == cp)
if (!cp)
cp = "(unknown)";
if (NULL == t)
if (!t)
Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
return t;
}
@ -162,7 +162,7 @@ static int jim_command_drscan(Jim_Interp *interp, int argc, Jim_Obj * const *arg
assert(e == JIM_OK);
tap = jtag_tap_by_jim_obj(interp, args[1]);
if (tap == NULL)
if (!tap)
return JIM_ERR;
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 (!found)
jteap = calloc(1, sizeof(*jteap));
else if (NULL != jteap->body)
else if (jteap->body)
Jim_DecrRefCount(goi->interp, jteap->body);
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;
t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
if (t == NULL)
if (!t)
return JIM_ERR;
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_getopt_obj(&goi, &o);
t = jtag_tap_by_jim_obj(goi.interp, o);
if (t == NULL)
if (!t)
return JIM_ERR;
return jtag_tap_configure_cmd(&goi, t);
@ -1122,7 +1122,7 @@ COMMAND_HANDLER(handle_irscan_command)
int retval;
for (i = 0; i < num_fields; i++) {
tap = jtag_tap_by_string(CMD_ARGV[i*2]);
if (tap == NULL) {
if (!tap) {
free(fields);
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)
{
if (tap == NULL)
if (!tap)
return ERROR_FAIL;
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;
tap = jtag_tap_by_string(CMD_ARGV[1]);
if (tap == NULL) {
if (!tap) {
command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
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");
if (input_file == NULL) {
if (!input_file) {
LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));
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;
const struct freertos_params *param;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) {
if (!rtos->symbols) {
LOG_ERROR("No symbols for FreeRTOS");
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;
int64_t stack_ptr = 0;
if (rtos == NULL)
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -1;
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;
const struct freertos_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
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;
if (param->fn_get_stacking_info != NULL)
if (param->fn_get_stacking_info)
return param->fn_get_stacking_info(rtos, stack_ptr);
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;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return 0; /* invalid */
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 (thread_id != 0);
@ -263,15 +263,15 @@ static int threadx_update_threads(struct rtos *rtos)
int thread_list_size = 0;
const struct threadx_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) {
if (!rtos->symbols) {
LOG_ERROR("No symbols for ThreadX");
return -4;
}
@ -437,13 +437,13 @@ static int threadx_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
int retval;
const struct threadx_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (!is_thread_id_valid(rtos, thread_id))
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
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 =
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);
return -6;
}
@ -518,18 +518,18 @@ static int threadx_get_thread_detail(struct rtos *rtos,
const struct threadx_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) {
if (!rtos->symbols) {
LOG_ERROR("No symbols for ThreadX");
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;
uint32_t stack_ptr = 0;
if ((rtos == NULL) || (thread_id == 0) ||
(rtos->rtos_specific_params == NULL))
if ((!rtos) || (thread_id == 0) ||
(!rtos->rtos_specific_params))
return -1;
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;
const struct ecos_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params;
if (rtos->symbols == NULL) {
if (!rtos->symbols) {
LOG_ERROR("No symbols for eCos");
return -4;
}
@ -289,13 +289,13 @@ static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
int retval;
const struct ecos_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
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;
const struct embkernel_params *param;
if (rtos == NULL)
if (!rtos)
return -1;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -3;
if (rtos->symbols == NULL) {
if (!rtos->symbols) {
LOG_ERROR("No symbols for embKernel");
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;
int64_t stack_ptr = 0;
if (rtos == NULL)
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (rtos->rtos_specific_params == NULL)
if (!rtos->rtos_specific_params)
return -1;
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;
enum target_debug_reason current_reason = DBG_REASON_UNDEFINED;
if (rtos == NULL)
if (!rtos)
return -1;
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)
{
/* Find the thread with that thread_id */
if (target == NULL)
if (!target)
return NULL;
if (target->smp) {
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,
struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size)
{
if (rtos == NULL)
if (!rtos)
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id);
if (curr == NULL)
if (!curr)
return ERROR_FAIL;
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,
uint32_t reg_num, struct rtos_reg *rtos_reg)
{
if (rtos == NULL)
if (!rtos)
return ERROR_FAIL;
struct target *target = rtos->target;
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);
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)
{
if (rtos == NULL)
if (!rtos)
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, rtos->current_thread);
if (curr == NULL)
if (!curr)
return ERROR_FAIL;
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 *curr = hwthread_find_thread(target, thread_id);
if (curr == NULL)
if (!curr)
return ERROR_FAIL;
*p_target = curr;

View File

@ -181,7 +181,7 @@ static int linux_os_thread_reg_list(struct rtos *rtos,
found = 1;
else
next = next->next;
} while ((found == 0) && (next != tmp) && (next != NULL));
} while ((found == 0) && (next != tmp) && (next));
if (found == 0) {
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;
/* invalid current threads content */
while (ctt != NULL) {
while (ctt) {
ctt->threadid = -1;
ctt->TS = 0xdeadbeef;
ctt = ctt->next;
@ -445,10 +445,10 @@ static int get_current(struct target *target, int create)
linux_os->current_threads;
cpu = head->target->coreid;
while ((ct != NULL) && (ct->core_id != (int32_t) cpu))
while ((ct) && (ct->core_id != (int32_t) cpu))
ct = ct->next;
if ((ct != NULL) && (ct->TS == 0xdeadbeef))
if ((ct) && (ct->TS == 0xdeadbeef))
ct->TS = TS;
else
LOG_ERROR
@ -603,13 +603,13 @@ static struct current_thread *add_current_thread(struct current_thread *currents
{
ct->next = NULL;
if (currents == NULL) {
if (!currents) {
currents = ct;
return currents;
} else {
struct current_thread *temp = currents;
while (temp->next != NULL)
while (temp->next)
temp = temp->next;
temp->next = ct;
@ -640,13 +640,13 @@ static struct threads *liste_add_task(struct threads *task_list, struct threads
t->next = NULL;
if (*last == NULL)
if (task_list == NULL) {
if (!task_list) {
task_list = t;
return task_list;
} else {
struct threads *temp = task_list;
while (temp->next != NULL)
while (temp->next)
temp = temp->next;
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;
#ifdef PID_CHECK
while ((ct != NULL) && (ct->pid != pid))
while ((ct) && (ct->pid != pid))
#else
while ((ct != NULL) && (ct->TS != base_addr))
while ((ct) && (ct->TS != base_addr))
#endif
ct = ct->next;
#ifdef PID_CHECK
if ((ct != NULL) && (ct->pid == pid))
if ((ct) && (ct->pid == pid))
#else
if ((ct != NULL) && (ct->TS == base_addr))
if ((ct) && (ct->TS == base_addr))
#endif
return 1;
@ -777,7 +777,7 @@ static int clean_threadlist(struct target *target)
target->rtos->rtos_specific_params;
struct threads *old, *temp = linux_os->thread_list;
while (temp != NULL) {
while (temp) {
old = temp;
free(temp->context);
@ -815,10 +815,10 @@ static int insert_into_threadlist(struct target *target, struct threads *t)
t->status = 1;
t->next = NULL;
if (temp == NULL)
if (!temp)
linux_os->thread_list = t;
else {
while (temp->next != NULL)
while (temp->next)
temp = temp->next;
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 threads *t = NULL;
while ((ct != NULL)) {
while ((ct)) {
if (ct->threadid == -1) {
/* un-identified thread */
@ -856,7 +856,7 @@ error_handling:
/* search in the list of threads if pid
already present */
while ((thread_list != NULL) && (found == 0)) {
while ((thread_list) && (found == 0)) {
#ifdef PID_CHECK
if (thread_list->pid == t->pid) {
#else
@ -926,7 +926,7 @@ static int linux_task_update(struct target *target, int context)
linux_os->thread_count = 0;
/*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*/
free(thread_list->context);
@ -967,7 +967,7 @@ static int linux_task_update(struct target *target, int context)
thread_list = linux_os->thread_list;
while (thread_list != NULL) {
while (thread_list) {
#ifdef PID_CHECK
if (t->pid == thread_list->pid) {
#else
@ -1058,7 +1058,7 @@ static int linux_gdb_thread_packet(struct target *target,
tmp_str += sprintf(tmp_str, "m");
struct threads *temp = linux_os->thread_list;
while (temp != NULL) {
while (temp) {
tmp_str += sprintf(tmp_str, "%016" PRIx64, temp->threadid);
temp = temp->next;
if (temp)
@ -1079,7 +1079,7 @@ static int linux_gdb_thread_update(struct target *target,
target->rtos->rtos_specific_params;
struct threads *temp = linux_os->thread_list;
while (temp != NULL) {
while (temp) {
if (temp->threadid == linux_os->preupdtate_threadid_count + 1) {
/*LOG_INFO("FOUND");*/
found = 1;
@ -1098,7 +1098,7 @@ static int linux_gdb_thread_update(struct target *target,
temp = temp->next;
while (temp != NULL) {
while (temp) {
/*LOG_INFO("INTO GDB THREAD UPDATE WHILE");*/
tmp_strr += sprintf(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);*/
struct threads *temp = linux_os->thread_list;
while (temp != NULL) {
while (temp) {
if (temp->threadid == threadid) {
char *pid = " 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 *prev = NULL;
while (temp != NULL) {
while (temp) {
if (temp->threadid == threadid) {
if (temp->status != 0) {
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);
struct threads *temp = linux_os->thread_list;
while (temp != NULL) {
while (temp) {
if (temp->threadid == threadid) {
if (temp->status == 1) {
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;
/* 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;
int64_t current_gdb_thread_rq;
if (linux_os->threads_lookup == 1) {
if ((ct != NULL) && (ct->threadid == -1)) {
if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1))
while ((ct) && (ct->threadid == -1))
ct = ct->next;
}
if (ct == NULL) {
if (!ct) {
/* no current thread can be identified
* any way with smp */
LOG_INFO("no current thread identified");
@ -1253,7 +1253,7 @@ static int linux_gdb_h_packet(struct connection *connection,
struct threads t;
ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1)) {
while ((ct) && (ct->threadid == -1)) {
t.base_addr = ct->TS;
get_name(target, &t);
LOG_INFO("name of unidentified thread %s",
@ -1321,7 +1321,7 @@ static int linux_thread_packet(struct connection *connection, char const *packet
break;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
if (linux_os->thread_list == NULL) {
if (!linux_os->thread_list) {
retval = linux_gdb_thread_packet(target,
connection,
packet,
@ -1356,17 +1356,17 @@ static int linux_thread_packet(struct connection *connection, char const *packet
if (linux_os->threads_lookup == 1) {
ct = linux_os->current_threads;
while ((ct != NULL) && (ct->core_id) != target->coreid)
while ((ct) && (ct->core_id) != target->coreid)
ct = ct->next;
if ((ct != NULL) && (ct->threadid == -1)) {
if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads;
while ((ct != NULL) && (ct->threadid == -1))
while ((ct) && (ct->threadid == -1))
ct = ct->next;
}
if ((ct != NULL) && (ct->threadid !=
if ((ct) && (ct->threadid !=
target->rtos->current_threadid)
&& (target->rtos->current_threadid != -1))
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, "---\t\t---\t\t----\t\t----\n");
while (temp != NULL) {
while (temp) {
if (temp->status) {
if (temp->context)
tmp +=

View File

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

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