target,flash: allow target_free_working_area on NULL area pointer
Standard C library free() allows NULL pointer as a parameter. Change target_free_working_area() to conform this convention. Remove NULL pointer tests before target_free_working_area() calls. While on it add missing setting pointer to NULL after target_free_working_area(). Change-Id: I7c692ab04a9933398ba5bc614723ad0bdecb87b3 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/6712 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
35f284fe7c
commit
f735faa931
|
@ -140,8 +140,9 @@ static int cc26xx_init(struct flash_bank *bank)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* Check for working area to use for flash helper algorithm */
|
/* Check for working area to use for flash helper algorithm */
|
||||||
if (cc26xx_bank->working_area)
|
target_free_working_area(target, cc26xx_bank->working_area);
|
||||||
target_free_working_area(target, cc26xx_bank->working_area);
|
cc26xx_bank->working_area = NULL;
|
||||||
|
|
||||||
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
|
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
|
||||||
&cc26xx_bank->working_area);
|
&cc26xx_bank->working_area);
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
|
@ -158,6 +159,7 @@ static int cc26xx_init(struct flash_bank *bank)
|
||||||
LOG_ERROR("%s: Failed to load flash helper algorithm",
|
LOG_ERROR("%s: Failed to load flash helper algorithm",
|
||||||
cc26xx_bank->family_name);
|
cc26xx_bank->family_name);
|
||||||
target_free_working_area(target, cc26xx_bank->working_area);
|
target_free_working_area(target, cc26xx_bank->working_area);
|
||||||
|
cc26xx_bank->working_area = NULL;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +174,7 @@ static int cc26xx_init(struct flash_bank *bank)
|
||||||
LOG_ERROR("%s: Failed to start flash helper algorithm",
|
LOG_ERROR("%s: Failed to start flash helper algorithm",
|
||||||
cc26xx_bank->family_name);
|
cc26xx_bank->family_name);
|
||||||
target_free_working_area(target, cc26xx_bank->working_area);
|
target_free_working_area(target, cc26xx_bank->working_area);
|
||||||
|
cc26xx_bank->working_area = NULL;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1359,9 +1359,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
|
||||||
|
|
||||||
/* free up resources */
|
/* free up resources */
|
||||||
cleanup:
|
cleanup:
|
||||||
if (source)
|
target_free_working_area(target, source);
|
||||||
target_free_working_area(target, source);
|
|
||||||
|
|
||||||
target_free_working_area(target, write_algorithm);
|
target_free_working_area(target, write_algorithm);
|
||||||
|
|
||||||
destroy_reg_param(®_params[0]);
|
destroy_reg_param(®_params[0]);
|
||||||
|
|
|
@ -661,10 +661,8 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (algorithm_wa) {
|
target_free_working_area(target, data_wa);
|
||||||
target_free_working_area(target, data_wa);
|
target_free_working_area(target, algorithm_wa);
|
||||||
target_free_working_area(target, algorithm_wa);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Switch to HW mode before return to prompt */
|
/* Switch to HW mode before return to prompt */
|
||||||
if (fespi_enable_hw_mode(bank) != ERROR_OK)
|
if (fespi_enable_hw_mode(bank) != ERROR_OK)
|
||||||
|
|
|
@ -335,8 +335,9 @@ static int msp432_init(struct flash_bank *bank)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for working area to use for flash helper algorithm */
|
/* Check for working area to use for flash helper algorithm */
|
||||||
if (msp432_bank->working_area)
|
target_free_working_area(target, msp432_bank->working_area);
|
||||||
target_free_working_area(target, msp432_bank->working_area);
|
msp432_bank->working_area = NULL;
|
||||||
|
|
||||||
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
|
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
|
||||||
&msp432_bank->working_area);
|
&msp432_bank->working_area);
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
|
|
|
@ -80,10 +80,8 @@ static int npcx_init(struct flash_bank *bank)
|
||||||
struct npcx_flash_bank *npcx_bank = bank->driver_priv;
|
struct npcx_flash_bank *npcx_bank = bank->driver_priv;
|
||||||
|
|
||||||
/* Check for working area to use for flash helper algorithm */
|
/* Check for working area to use for flash helper algorithm */
|
||||||
if (npcx_bank->working_area) {
|
target_free_working_area(target, npcx_bank->working_area);
|
||||||
target_free_working_area(target, npcx_bank->working_area);
|
npcx_bank->working_area = NULL;
|
||||||
npcx_bank->working_area = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int retval = target_alloc_working_area(target, npcx_bank->algo_working_size,
|
int retval = target_alloc_working_area(target, npcx_bank->algo_working_size,
|
||||||
&npcx_bank->working_area);
|
&npcx_bank->working_area);
|
||||||
|
|
|
@ -182,10 +182,8 @@ destroy_rp_free_wa:
|
||||||
/* Something went wrong, do some cleanup */
|
/* Something went wrong, do some cleanup */
|
||||||
destroy_reg_param(®_params);
|
destroy_reg_param(®_params);
|
||||||
|
|
||||||
if (g_stack_area) {
|
target_free_working_area(target, g_stack_area);
|
||||||
target_free_working_area(target, g_stack_area);
|
g_stack_area = NULL;
|
||||||
g_stack_area = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -703,11 +703,14 @@ static int sh_qspi_upload_helper(struct flash_bank *bank)
|
||||||
};
|
};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (info->source)
|
target_free_working_area(target, info->source);
|
||||||
target_free_working_area(target, info->source);
|
target_free_working_area(target, info->io_algorithm);
|
||||||
if (info->io_algorithm)
|
|
||||||
target_free_working_area(target, info->io_algorithm);
|
|
||||||
|
|
||||||
|
/* FIXME: Working areas are allocated during flash probe
|
||||||
|
* and eventual target_free_all_working_areas() called in case
|
||||||
|
* of target reset or run is not handled at all.
|
||||||
|
* Not a big problem if area backp is off.
|
||||||
|
*/
|
||||||
/* flash write code */
|
/* flash write code */
|
||||||
if (target_alloc_working_area(target, sizeof(sh_qspi_io_code),
|
if (target_alloc_working_area(target, sizeof(sh_qspi_io_code),
|
||||||
&info->io_algorithm) != ERROR_OK) {
|
&info->io_algorithm) != ERROR_OK) {
|
||||||
|
|
|
@ -1199,10 +1199,7 @@ static int scratch_reserve(struct target *target,
|
||||||
static int scratch_release(struct target *target,
|
static int scratch_release(struct target *target,
|
||||||
scratch_mem_t *scratch)
|
scratch_mem_t *scratch)
|
||||||
{
|
{
|
||||||
if (scratch->area)
|
return target_free_working_area(target, scratch->area);
|
||||||
return target_free_working_area(target, scratch->area);
|
|
||||||
|
|
||||||
return ERROR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scratch_read64(struct target *target, scratch_mem_t *scratch,
|
static int scratch_read64(struct target *target, scratch_mem_t *scratch,
|
||||||
|
|
|
@ -2148,11 +2148,10 @@ static int target_restore_working_area(struct target *target, struct working_are
|
||||||
/* Restore the area's backup memory, if any, and return the area to the allocation pool */
|
/* Restore the area's backup memory, if any, and return the area to the allocation pool */
|
||||||
static int target_free_working_area_restore(struct target *target, struct working_area *area, int restore)
|
static int target_free_working_area_restore(struct target *target, struct working_area *area, int restore)
|
||||||
{
|
{
|
||||||
|
if (!area || area->free)
|
||||||
|
return ERROR_OK;
|
||||||
|
|
||||||
int retval = ERROR_OK;
|
int retval = ERROR_OK;
|
||||||
|
|
||||||
if (area->free)
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
if (restore) {
|
if (restore) {
|
||||||
retval = target_restore_working_area(target, area);
|
retval = target_restore_working_area(target, area);
|
||||||
/* REVISIT: Perhaps the area should be freed even if restoring fails. */
|
/* REVISIT: Perhaps the area should be freed even if restoring fails. */
|
||||||
|
@ -6401,8 +6400,7 @@ next:
|
||||||
out:
|
out:
|
||||||
free(test_pattern);
|
free(test_pattern);
|
||||||
|
|
||||||
if (wa)
|
target_free_working_area(target, wa);
|
||||||
target_free_working_area(target, wa);
|
|
||||||
|
|
||||||
/* Test writes */
|
/* Test writes */
|
||||||
num_bytes = test_size + 4 + 4 + 4;
|
num_bytes = test_size + 4 + 4 + 4;
|
||||||
|
@ -6486,8 +6484,7 @@ nextw:
|
||||||
|
|
||||||
free(test_pattern);
|
free(test_pattern);
|
||||||
|
|
||||||
if (wa)
|
target_free_working_area(target, wa);
|
||||||
target_free_working_area(target, wa);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -726,6 +726,13 @@ int target_alloc_working_area(struct target *target,
|
||||||
*/
|
*/
|
||||||
int target_alloc_working_area_try(struct target *target,
|
int target_alloc_working_area_try(struct target *target,
|
||||||
uint32_t size, struct working_area **area);
|
uint32_t size, struct working_area **area);
|
||||||
|
/**
|
||||||
|
* Free a working area.
|
||||||
|
* Restore target data if area backup is configured.
|
||||||
|
* @param target
|
||||||
|
* @param area Pointer to the area to be freed or NULL
|
||||||
|
* @returns ERROR_OK if successful; error code if restore failed
|
||||||
|
*/
|
||||||
int target_free_working_area(struct target *target, struct working_area *area);
|
int target_free_working_area(struct target *target, struct working_area *area);
|
||||||
void target_free_all_working_areas(struct target *target);
|
void target_free_all_working_areas(struct target *target);
|
||||||
uint32_t target_get_working_area_avail(struct target *target);
|
uint32_t target_get_working_area_avail(struct target *target);
|
||||||
|
|
Loading…
Reference in New Issue