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;
}

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