diff --git a/src/flash/nand/fileio.c b/src/flash/nand/fileio.c index 1279e45a4..fee401292 100644 --- a/src/flash/nand/fileio.c +++ b/src/flash/nand/fileio.c @@ -99,14 +99,11 @@ int nand_fileio_cleanup(struct nand_fileio_state *state) if (state->file_opened) fileio_close(state->fileio); - if (state->oob) { - free(state->oob); - state->oob = NULL; - } - if (state->page) { - free(state->page); - state->page = NULL; - } + free(state->oob); + state->oob = NULL; + + free(state->page); + state->page = NULL; return ERROR_OK; } int nand_fileio_finish(struct nand_fileio_state *state) diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c index 622943d28..28dc42d82 100644 --- a/src/flash/nor/ambiqmicro.c +++ b/src/flash/nor/ambiqmicro.c @@ -672,10 +672,7 @@ static int ambiqmicro_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages; diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index 1e2a074aa..c9baffc70 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -3530,8 +3530,7 @@ static int sam3_write(struct flash_bank *bank, LOG_DEBUG("Done!"); r = ERROR_OK; done: - if (pagebuffer) - free(pagebuffer); + free(pagebuffer); return r; } diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 4be3a5962..3f9ea9bfa 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -3009,8 +3009,7 @@ static int sam4_write(struct flash_bank *bank, LOG_DEBUG("Done!"); r = ERROR_OK; done: - if (pagebuffer) - free(pagebuffer); + free(pagebuffer); return r; } diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index 63710d3e0..5fbf8bcaa 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -915,9 +915,7 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer, } free_pb: - if (pb) - free(pb); - + free(pb); return res; } diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 82306830a..5d6010a2a 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -731,9 +731,7 @@ static int same5_write(struct flash_bank *bank, const uint8_t *buffer, } free_pb: - if (pb) - free(pb); - + free(pb); return res; } diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 4ec1161af..70d4d341b 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -333,10 +333,7 @@ static int avrf_probe(struct flash_bank *bank) } if (avr_info != NULL) { - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* chip found */ bank->base = 0x00000000; diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c index 5e88aa61b..5427bd3a9 100644 --- a/src/flash/nor/cc3220sf.c +++ b/src/flash/nor/cc3220sf.c @@ -438,10 +438,7 @@ static int cc3220sf_probe(struct flash_bank *bank) size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE; num_sectors = FLASH_NUM_SECTORS; - if (NULL != bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); if (NULL == bank->sectors) diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index 887821b79..964e06ac7 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -423,8 +423,7 @@ static int cfi_read_intel_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_intel_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_intel_pri_ext)); if (pri_ext == NULL) { @@ -520,8 +519,7 @@ static int cfi_read_spansion_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_spansion_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); if (pri_ext == NULL) { @@ -623,8 +621,7 @@ static int cfi_read_atmel_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_spansion_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); if (pri_ext == NULL) { @@ -2593,14 +2590,12 @@ int cfi_probe(struct flash_bank *bank) cfi_info->probed = false; cfi_info->num_erase_regions = 0; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } - if (cfi_info->erase_region_info) { - free(cfi_info->erase_region_info); - cfi_info->erase_region_info = NULL; - } + + free(bank->sectors); + bank->sectors = NULL; + + free(cfi_info->erase_region_info); + cfi_info->erase_region_info = NULL; /* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses, * while CFI compatible AMD/Spansion flashes use 0x555 and 0x2aa diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index 2c323b07e..6f2900762 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -951,9 +951,7 @@ reset_pg_and_lock: retval = retval2; cleanup: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -987,10 +985,8 @@ static int efm32x_probe(struct flash_bank *bank) assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; bank->base = base_address; bank->size = (num_pages * efm32_mcu_info.page_size); diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c index cb4456209..4e2a169c6 100644 --- a/src/flash/nor/em357.c +++ b/src/flash/nor/em357.c @@ -724,10 +724,7 @@ static int em357_probe(struct flash_bank *bank) LOG_INFO("flash size = %dkbytes", num_pages*page_size/1024); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->base = base_address; bank->size = (num_pages * page_size); diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 43b90f1f0..6b6121d3b 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -2736,14 +2736,11 @@ static int kinetis_probe(struct flash_bank *bank) " please report to OpenOCD mailing list", fcfg2_maxaddr1); } - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } - if (bank->prot_blocks) { - free(bank->prot_blocks); - bank->prot_blocks = NULL; - } + free(bank->sectors); + bank->sectors = NULL; + + free(bank->prot_blocks); + bank->prot_blocks = NULL; if (k_bank->sector_size == 0) { LOG_ERROR("Unknown sector size for bank %u", bank->bank_number); diff --git a/src/flash/nor/kinetis_ke.c b/src/flash/nor/kinetis_ke.c index 6afb3b9e6..349b2564d 100644 --- a/src/flash/nor/kinetis_ke.c +++ b/src/flash/nor/kinetis_ke.c @@ -1145,10 +1145,7 @@ static int kinetis_ke_probe(struct flash_bank *bank) break; } - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); assert(bank->num_sectors > 0); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index c840bd795..bf54f63ba 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -651,10 +651,7 @@ static int max32xxx_probe(struct flash_bank *bank) uint32_t arm_id[2]; uint16_t arm_pid; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = info->flash_size; diff --git a/src/flash/nor/mdr.c b/src/flash/nor/mdr.c index b835f9237..2518c229b 100644 --- a/src/flash/nor/mdr.c +++ b/src/flash/nor/mdr.c @@ -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); diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c index 0c925bdd3..d2417bc89 100644 --- a/src/flash/nor/msp432.c +++ b/src/flash/nor/msp432.c @@ -902,10 +902,8 @@ static int msp432_probe(struct flash_bank *bank) } } - if (NULL != bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; if (num_sectors > 0) { bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); @@ -1046,7 +1044,7 @@ static void msp432_flash_free_driver_priv(struct flash_bank *bank) /* A single private struct is shared between main and info banks */ /* Only free it on the call for main bank */ - if (is_main && (NULL != bank->driver_priv)) + if (is_main) free(bank->driver_priv); /* Forget about the private struct on both main and info banks */ diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c index 2377e14f7..2a20edcee 100644 --- a/src/flash/nor/niietcm4.c +++ b/src/flash/nor/niietcm4.c @@ -1469,9 +1469,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer, } free_buffer: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -1681,10 +1679,9 @@ static int niietcm4_probe(struct flash_bank *bank) struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv; struct target *target = bank->target; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; + uint32_t retval; uint32_t chipid; diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index 9b9185344..ae5ebb932 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -591,8 +591,7 @@ static int pic32mx_write_block(struct flash_bank *bank, const uint8_t *buffer, destroy_reg_param(®_params[1]); destroy_reg_param(®_params[2]); - if (new_buffer != NULL) - free(new_buffer); + free(new_buffer); return retval; } @@ -774,10 +773,7 @@ static int pic32mx_probe(struct flash_bank *bank) LOG_INFO("flash size = %" PRId32 "kbytes", num_pages / 1024); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* calculate numbers of pages */ num_pages /= page_size; diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c index 0c656349f..9c2fdf775 100644 --- a/src/flash/nor/psoc4.c +++ b/src/flash/nor/psoc4.c @@ -610,8 +610,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, unsigned int first, break; } - if (sysrq_buffer) - free(sysrq_buffer); + free(sysrq_buffer); psoc4_protect_check(bank); return retval; @@ -714,9 +713,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer, cleanup: jtag_poll_set_enabled(save_poll); - if (sysrq_buffer) - free(sysrq_buffer); - + free(sysrq_buffer); return retval; } @@ -827,9 +824,7 @@ static int psoc4_probe(struct flash_bank *bank) } } - if (bank->sectors) { - free(bank->sectors); - } + free(bank->sectors); psoc4_info->family_id = family_id; psoc4_info->num_macros = num_macros; diff --git a/src/flash/nor/psoc6.c b/src/flash/nor/psoc6.c index c7141738d..09a1bed56 100644 --- a/src/flash/nor/psoc6.c +++ b/src/flash/nor/psoc6.c @@ -585,10 +585,8 @@ static int psoc6_probe(struct flash_bank *bank) /* Calculate size of Main Flash*/ uint32_t flash_sz_bytes = bank_cnt * row_cnt * row_sz; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; size_t bank_size = 0; diff --git a/src/flash/nor/sim3x.c b/src/flash/nor/sim3x.c index 21449041c..76280f1ab 100644 --- a/src/flash/nor/sim3x.c +++ b/src/flash/nor/sim3x.c @@ -801,10 +801,7 @@ static int sim3x_probe(struct flash_bank *bank) if (ret != ERROR_OK) return ret; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->base = FLASH_BASE_ADDRESS; bank->size = sim3x_info->flash_size_kb * SIM3X_FLASH_PAGE_SIZE; diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 34c9c28fe..55b99de3f 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -1250,10 +1250,7 @@ static int stellaris_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = stellaris_info->num_pages * stellaris_info->pagesize; diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c index a07bd847b..78efc8b47 100644 --- a/src/flash/nor/stm32f1x.c +++ b/src/flash/nor/stm32f1x.c @@ -617,9 +617,7 @@ reset_pg_and_lock: retval = retval2; cleanup: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -872,15 +870,11 @@ static int stm32x_probe(struct flash_bank *bank) /* check that calculation result makes sense */ assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; - if (bank->prot_blocks) { - free(bank->prot_blocks); - bank->prot_blocks = NULL; - } + free(bank->prot_blocks); + bank->prot_blocks = NULL; bank->base = base_address; bank->size = (num_pages * page_size); diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c index 52bad4b0d..e3625f322 100644 --- a/src/flash/nor/stm32f2x.c +++ b/src/flash/nor/stm32f2x.c @@ -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)) { diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 9f456b29d..ac7d75948 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -853,8 +853,7 @@ static int stm32x_probe(struct flash_bank *bank) bank->num_sectors = flash_size_in_kb / stm32x_info->part_info->page_size_kb; assert(bank->num_sectors > 0); - if (bank->sectors) - free(bank->sectors); + free(bank->sectors); bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024, bank->num_sectors); @@ -871,8 +870,7 @@ static int stm32x_probe(struct flash_bank *bank) bank->num_prot_blocks = bank->num_sectors / wpsn; assert(bank->num_prot_blocks > 0); - if (bank->prot_blocks) - free(bank->prot_blocks); + free(bank->prot_blocks); bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024, bank->num_prot_blocks); diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index c56bd6d60..0b5e1b04b 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -1040,10 +1040,7 @@ static int stm32l4_probe(struct flash_bank *bank) assert((stm32l4_info->wrpxxr_mask & 0xFFFF0000) == 0); LOG_DEBUG("WRPxxR mask 0x%04" PRIx16, (uint16_t)stm32l4_info->wrpxxr_mask); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->size = (flash_size_kb + gap_size_kb) * 1024; bank->base = STM32_FLASH_BANK_BASE; diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index cf5b36040..34c7408b0 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -836,10 +836,7 @@ static int stm32lx_probe(struct flash_bank *bank) /* calculate numbers of sectors (4kB per sector) */ unsigned int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->size = flash_size_in_kb * 1024; bank->base = base_address; diff --git a/src/flash/nor/swm050.c b/src/flash/nor/swm050.c index 020a1dac7..98361eb91 100644 --- a/src/flash/nor/swm050.c +++ b/src/flash/nor/swm050.c @@ -156,10 +156,7 @@ COMMAND_HANDLER(swm050_handle_mass_erase_command) FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command) { - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->write_start_alignment = 4; bank->write_end_alignment = 4; bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES; diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 4b8d2208a..611688c6a 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 diff --git a/src/flash/nor/w600.c b/src/flash/nor/w600.c index 479082177..043959326 100644 --- a/src/flash/nor/w600.c +++ b/src/flash/nor/w600.c @@ -331,10 +331,8 @@ static int w600_probe(struct flash_bank *bank) /* check that calculation result makes sense */ assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; bank->base = W600_FLASH_BASE; bank->size = num_pages * W600_FLASH_SECSIZE;