Skip to contentSkip to conversation

env: sf: Free the old env_flash

PATCH New Jagan Teki 2 participants 2 messages Jun 1, 2020 – Jun 4, 2020

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH v2 1/1 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.

---
Changes for v2:
- change suggested by Pratyush.

 env/sf.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
env/sf.c +6 -7
index 23de5a3495..02ed846fc7 100644
@@ -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;
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 env: sf: Free the old env_flash

Quoted 9 lines · Jagan Teki

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.

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India