From 62329444abc89ad3b37fbb4ebc2edfd1dee23351 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 17 Aug 2020 10:08:35 +0200 Subject: 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 Reviewed-on: http://openocd.zylin.com/5811 Tested-by: jenkins --- src/flash/nor/tms470.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/flash/nor/tms470.c') diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 4b8d220..611688c 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -148,11 +148,9 @@ static int tms470_read_part_info(struct flash_bank *bank) rom_flash = (device_ident_reg >> 10) & 1; part_number = (device_ident_reg >> 3) & 0x7f; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - bank->num_sectors = 0; - } + free(bank->sectors); + bank->sectors = NULL; + bank->num_sectors = 0; /* * If the part number is known, determine if the flash bank is valid -- cgit v1.1