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:
@@ -458,8 +458,7 @@ reset_pg_and_lock:
|
||||
retval = retval2;
|
||||
|
||||
free_buffer:
|
||||
if (new_buffer)
|
||||
free(new_buffer);
|
||||
free(new_buffer);
|
||||
|
||||
/* read some bytes bytes to flush buffer in flash accelerator.
|
||||
* See errata for 1986VE1T and 1986VE3. Error 0007 */
|
||||
@@ -573,10 +572,7 @@ static int mdr_probe(struct flash_bank *bank)
|
||||
page_count = mdr_info->page_count;
|
||||
page_size = bank->size / page_count;
|
||||
|
||||
if (bank->sectors) {
|
||||
free(bank->sectors);
|
||||
bank->sectors = NULL;
|
||||
}
|
||||
free(bank->sectors);
|
||||
|
||||
bank->num_sectors = page_count;
|
||||
bank->sectors = malloc(sizeof(struct flash_sector) * page_count);
|
||||
|
||||
Reference in New Issue
Block a user