Skip to contentSkip to conversation

common: env_nand: Ensure that we have nand_info[0] prior to use

PATCH Superseded Tom Rini 1 participant 1 message Aug 15, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use

Now that nand_info[] is an array of pointers we need to ensure that it's been populated prior to use. We may for example have ENV in NAND set in configurations that run on boards with and without NAND (where default env is fine enough, such as omap3_beagle and beagleboard (NAND) vs beagle xM (no NAND)).

Fixes b616d9b0a708 ("nand: Embed mtd_info in struct nand_chip")
Cc Scott Wood <[email protected]>
---
 common/env_nand.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/env_nand.c +7 -2
index fc99a5e3fc0d..9a2dec187690 100644
@@ -132,6 +132,9 @@ static int writeenv(size_t offset, u_char *buf)
 	size_t blocksize, len;
 	u_char *char_ptr;
 
+	if (!nand_info[0])
+		return 1;
+
 	blocksize = nand_info[0]->erasesize;
 	len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
 
@@ -244,10 +247,12 @@ static int readenv(size_t offset, u_char *buf)
 {
 	size_t end = offset + CONFIG_ENV_RANGE;
 	size_t amount_loaded = 0;
-	size_t blocksize, len;
+	size_t blocksize = 0, len;
 	u_char *char_ptr;
 
-	blocksize = nand_info[0]->erasesize;
+	if (nand_info[0])
+		blocksize = nand_info[0]->erasesize;
+
 	if (!blocksize)
 		return 1;
 
Signature · 1 line
1.9.1