Browse Source

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
jim
Antonio Borneo 1 year ago
parent
commit
08ee7bb982
100 changed files with 509 additions and 509 deletions
  1. +1
    -1
      src/flash/common.c
  2. +1
    -1
      src/flash/nand/davinci.c
  3. +4
    -4
      src/flash/nand/fileio.c
  4. +1
    -1
      src/flash/nand/mx3.c
  5. +1
    -1
      src/flash/nand/mxc.c
  6. +1
    -1
      src/flash/nand/s3c24xx.c
  7. +8
    -8
      src/flash/nand/tcl.c
  8. +4
    -4
      src/flash/nor/at91sam3.c
  9. +5
    -5
      src/flash/nor/at91sam4.c
  10. +3
    -3
      src/flash/nor/at91samd.c
  11. +2
    -2
      src/flash/nor/atsame5.c
  12. +2
    -2
      src/flash/nor/avrf.c
  13. +1
    -1
      src/flash/nor/bluenrg-x.c
  14. +3
    -3
      src/flash/nor/cc26xx.c
  15. +2
    -2
      src/flash/nor/cc3220sf.c
  16. +6
    -6
      src/flash/nor/cfi.c
  17. +8
    -8
      src/flash/nor/core.c
  18. +3
    -3
      src/flash/nor/efm32.c
  19. +3
    -3
      src/flash/nor/faux.c
  20. +2
    -2
      src/flash/nor/fespi.c
  21. +3
    -3
      src/flash/nor/jtagspi.c
  22. +10
    -10
      src/flash/nor/kinetis.c
  23. +2
    -2
      src/flash/nor/kinetis_ke.c
  24. +2
    -2
      src/flash/nor/lpcspifi.c
  25. +1
    -1
      src/flash/nor/mdr.c
  26. +2
    -2
      src/flash/nor/mrvlqspi.c
  27. +4
    -4
      src/flash/nor/msp432.c
  28. +1
    -1
      src/flash/nor/niietcm4.c
  29. +8
    -8
      src/flash/nor/nrf5.c
  30. +1
    -1
      src/flash/nor/numicro.c
  31. +1
    -1
      src/flash/nor/pic32mx.c
  32. +4
    -4
      src/flash/nor/psoc4.c
  33. +1
    -1
      src/flash/nor/psoc5lp.c
  34. +2
    -2
      src/flash/nor/sfdp.c
  35. +4
    -4
      src/flash/nor/sim3x.c
  36. +2
    -2
      src/flash/nor/stm32f1x.c
  37. +1
    -1
      src/flash/nor/stm32f2x.c
  38. +3
    -3
      src/flash/nor/stm32h7x.c
  39. +1
    -1
      src/flash/nor/stm32l4x.c
  40. +4
    -4
      src/flash/nor/stm32lx.c
  41. +3
    -3
      src/flash/nor/stmqspi.c
  42. +2
    -2
      src/flash/nor/stmsmi.c
  43. +5
    -5
      src/flash/nor/str9xpec.c
  44. +11
    -11
      src/flash/nor/tcl.c
  45. +12
    -12
      src/flash/nor/virtual.c
  46. +2
    -2
      src/flash/nor/xcf.c
  47. +1
    -1
      src/flash/nor/xmc4xxx.c
  48. +16
    -16
      src/helper/command.c
  49. +4
    -4
      src/helper/configuration.c
  50. +5
    -5
      src/helper/jim-nvp.c
  51. +7
    -7
      src/helper/log.c
  52. +7
    -7
      src/helper/options.c
  53. +4
    -4
      src/helper/replacements.c
  54. +1
    -1
      src/jtag/aice/aice_transport.c
  55. +14
    -14
      src/jtag/aice/aice_usb.c
  56. +1
    -1
      src/jtag/commands.c
  57. +15
    -15
      src/jtag/core.c
  58. +1
    -1
      src/jtag/drivers/arm-jtag-ew.c
  59. +1
    -1
      src/jtag/drivers/bitq.c
  60. +2
    -2
      src/jtag/drivers/buspirate.c
  61. +5
    -5
      src/jtag/drivers/cmsis_dap.c
  62. +3
    -3
      src/jtag/drivers/cmsis_dap_usb_bulk.c
  63. +8
    -8
      src/jtag/drivers/cmsis_dap_usb_hid.c
  64. +2
    -2
      src/jtag/drivers/driver.c
  65. +3
    -3
      src/jtag/drivers/ft232r.c
  66. +2
    -2
      src/jtag/drivers/ftdi.c
  67. +1
    -1
      src/jtag/drivers/jlink.c
  68. +11
    -11
      src/jtag/drivers/jtag_dpi.c
  69. +2
    -2
      src/jtag/drivers/jtag_usb_common.c
  70. +8
    -8
      src/jtag/drivers/kitprog.c
  71. +1
    -1
      src/jtag/drivers/libusb_helper.c
  72. +14
    -14
      src/jtag/drivers/linuxgpiod.c
  73. +2
    -2
      src/jtag/drivers/mpsse.c
  74. +3
    -3
      src/jtag/drivers/opendous.c
  75. +3
    -3
      src/jtag/drivers/openjtag.c
  76. +1
    -1
      src/jtag/drivers/parport.c
  77. +1
    -1
      src/jtag/drivers/presto.c
  78. +3
    -3
      src/jtag/drivers/remote_bitbang.c
  79. +3
    -3
      src/jtag/drivers/rlink.c
  80. +49
    -49
      src/jtag/drivers/stlink_usb.c
  81. +2
    -2
      src/jtag/drivers/ti_icdi_usb.c
  82. +21
    -21
      src/jtag/drivers/ulink.c
  83. +3
    -3
      src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c
  84. +5
    -5
      src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c
  85. +13
    -13
      src/jtag/drivers/versaloon/versaloon.c
  86. +3
    -3
      src/jtag/drivers/vsllink.c
  87. +17
    -17
      src/jtag/drivers/xds110.c
  88. +1
    -1
      src/jtag/hla/hla_interface.c
  89. +1
    -1
      src/jtag/hla/hla_layout.c
  90. +7
    -7
      src/jtag/tcl.c
  91. +2
    -2
      src/pld/virtex2.c
  92. +1
    -1
      src/pld/xilinx_bit.c
  93. +6
    -6
      src/rtos/FreeRTOS.c
  94. +12
    -12
      src/rtos/ThreadX.c
  95. +2
    -2
      src/rtos/chibios.c
  96. +5
    -5
      src/rtos/eCos.c
  97. +5
    -5
      src/rtos/embKernel.c
  98. +9
    -9
      src/rtos/hwthread.c
  99. +36
    -36
      src/rtos/linux.c
  100. +1
    -1
      src/rtos/mqx.c

+ 1
- 1
src/flash/common.c 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;


+ 1
- 1
src/flash/nand/davinci.c 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;


+ 4
- 4
src/flash/nand/fileio.c 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);


+ 1
- 1
src/flash/nand/mx3.c 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;
}


+ 1
- 1
src/flash/nand/mxc.c 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;
}


+ 1
- 1
src/flash/nand/s3c24xx.c 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;
}


+ 8
- 8
src/flash/nand/tcl.c 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);
}


+ 4
- 4
src/flash/nor/at91sam3.c 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;
}


+ 5
- 5
src/flash/nor/at91sam4.c 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;
}


+ 3
- 3
src/flash/nor/at91samd.c 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;
}


+ 2
- 2
src/flash/nor/atsame5.c 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;
}


+ 2
- 2
src/flash/nor/avrf.c 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));


+ 1
- 1
src/flash/nor/bluenrg-x.c 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;
}


+ 3
- 3
src/flash/nor/cc26xx.c 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;


+ 2
- 2
src/flash/nor/cc3220sf.c 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;


+ 6
- 6
src/flash/nor/cfi.c 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;
}


+ 8
- 8
src/flash/nor/core.c 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++) {


+ 3
- 3
src/flash/nor/efm32.c 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);


+ 3
- 3
src/flash/nor/faux.c 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);


+ 2
- 2
src/flash/nor/fespi.c 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;
}


+ 3
- 3
src/flash/nor/jtagspi.c 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;
}


+ 10
- 10
src/flash/nor/kinetis.c 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;
}


+ 2
- 2
src/flash/nor/kinetis_ke.c 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;


+ 2
- 2
src/flash/nor/lpcspifi.c 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;
}


+ 1
- 1
src/flash/nor/mdr.c 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;
}


+ 2
- 2
src/flash/nor/mrvlqspi.c 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;
}


+ 4
- 4
src/flash/nor/msp432.c 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 */


+ 1
- 1
src/flash/nor/niietcm4.c 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;
}


+ 8
- 8
src/flash/nor/nrf5.c 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;



+ 1
- 1
src/flash/nor/numicro.c 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;


+ 1
- 1
src/flash/nor/pic32mx.c 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;
}


+ 4
- 4
src/flash/nor/psoc4.c 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);


+ 1
- 1
src/flash/nor/psoc5lp.c 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++) {


+ 2
- 2
src/flash/nor/sfdp.c 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;


+ 4
- 4
src/flash/nor/sim3x.c 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;


+ 2
- 2
src/flash/nor/stm32f1x.c 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);


+ 1
- 1
src/flash/nor/stm32f2x.c 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);


+ 3
- 3
src/flash/nor/stm32h7x.c 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 {


+ 1
- 1
src/flash/nor/stm32l4x.c 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;
}


+ 4
- 4
src/flash/nor/stm32lx.c 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);


+ 3
- 3
src/flash/nor/stmqspi.c 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;


+ 2
- 2
src/flash/nor/stmsmi.c 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;
}


+ 5
- 5
src/flash/nor/str9xpec.c 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 */


+ 11
- 11
src/flash/nor/tcl.c 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);


+ 12
- 12
src/flash/nor/virtual.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 */


+ 2
- 2
src/flash/nor/xcf.c 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;
}


+ 1
- 1
src/flash/nor/xmc4xxx.c 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);


+ 16
- 16
src/helper/command.c 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 */


+ 4
- 4
src/helper/configuration.c 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;


+ 5
- 5
src/helper/jim-nvp.c 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)


+ 7
- 7
src/helper/log.c 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;
}