flash: avoid checking for non NULL pointer to free it

The function free() can be called with a NULL pointer as argument,
no need to check the argument before. If the pointer is NULL, no
operation is performed by free().

Remove the occurrences of pattern:
	if (ptr)
		free(ptr);

There are cases where the pointer is set to NULL after free(), but
then re-assigned within few lines. Drop the setting to NULL when
this is evident. Anyway, the compiler will remove the useless
assignment so no reason to be too much aggressive in this change.

Change-Id: I55b2ce7cbe201410016398933e34d33a4b66e30b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5811
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2020-08-17 10:08:35 +02:00
parent 47d29ebe11
commit 62329444ab
30 changed files with 71 additions and 161 deletions

View File

@@ -1013,17 +1013,13 @@ static int stm32x_probe(struct flash_bank *bank)
stm32x_info->protection_bits = 12; /* max. number of nWRPi bits (in FLASH_OPTCR !!!) */
num_prot_blocks = 0;
if (bank->sectors) {
free(bank->sectors);
bank->num_sectors = 0;
bank->sectors = NULL;
}
free(bank->sectors);
bank->num_sectors = 0;
bank->sectors = NULL;
if (bank->prot_blocks) {
free(bank->prot_blocks);
bank->num_prot_blocks = 0;
bank->prot_blocks = NULL;
}
free(bank->prot_blocks);
bank->num_prot_blocks = 0;
bank->prot_blocks = NULL;
/* if explicitly called out as OTP bank, short circuit probe */
if (stm32x_is_otp(bank)) {