From: Jagan Teki Date: Wed, 13 May 2020 11:02:42 +0000 (+0530) Subject: env: sf: Free the old env_flash X-Git-Tag: v2020.10~182^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8cbf1707cba99cfdf1a6a33e03956a5a788183a;p=platform%2Fkernel%2Fu-boot.git env: sf: Free the old env_flash env_flash is a global flash pointer, and the probe would happen only if env_flash is NULL, but there is no checking and free the pointer if is not NULL. So, this patch frees the old env_flash, and get the probed flash in to env_flash pointer and finally check if is not NULL. Cc: Simon Glass Cc: Vignesh R Signed-off-by: Jagan Teki --- diff --git a/env/sf.c b/env/sf.c index 23de5a3..02ed846 100644 --- a/env/sf.c +++ b/env/sf.c @@ -53,15 +53,14 @@ static int setup_flash_device(void) env_flash = dev_get_uclass_priv(new); #else + if (env_flash) + spi_flash_free(env_flash); + env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!env_flash) { - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, - CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - env_set_default("spi_flash_probe() failed", 0); - return -EIO; - } + env_set_default("spi_flash_probe() failed", 0); + return -EIO; } #endif return 0;