common: env_nand: Ensure that we have nand_info[0] prior to use
PATCH v2 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)).
---
Changes in v2:
- Oops, move check on the saveenv side in to erase_and_write_env
--- common/env_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
common/env_nand.c +7 -2
@@ -163,6 +163,9 @@ static int erase_and_write_env(const struct env_location *location, {int ret =0 ; +if (!nand_info[0 ]) +return 1 ; +printf ("Erasing %s...\n" , location->name);if (nand_erase_opts (nand_info[0 ], &location->erase_opts))return 1 ;
@@ -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
PATCH v2 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use
Quoted 43 lines · Tom Rini
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_beagleand beagleboard (NAND) vs beagle xM (no NAND)).Fixes b616d9b0a708 ("nand: Embed mtd_info in struct nand_chip")Cc Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- Oops, move check on the saveenv side in toerase_and_write_env
---
?common/env_nand.c | 9 +++++++--
?1 file changed, 7 insertions(+), 2 deletions(-)common/env_nand.c +0
-0@@ -163,6 +163,9 @@ static int erase_and_write_env(const struct env_location *location, ?{ ? int ret = 0;?
common/env_nand.c +3
-0+if (!nand_info[0 ]) +return 1 ; +?
printf("Erasing %s...\n", location->name);
? if (nand_erase_opts(nand_info[0], &location->erase_opts))
? return 1;common/env_nand.c +1
-1@@ -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;?
common/env_nand.c +3
-1- blocksize = nand_info[0 ]->erasesize; +if (nand_info[0 ]) + blocksize = nand_info[0 ]->erasesize; +
Quoted 3 lines
? if (!blocksize)
? return 1;
?
Messing around with blocksize rather than directly returning is awkward -- it makes it look as if you could proceed with blocksize zero until you read the next statement. ?And is there ever a case where blocksize can be zero, now that uninitialized NAND devices will simply have a NULL pointer?
-Scott
PATCH v2 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use
Quoted 44 lines · Scott Wood
Quoted 43 lines · Tom Rini
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_beagleand beagleboard (NAND) vs beagle xM (no NAND)).Fixes b616d9b0a708 ("nand: Embed mtd_info in struct nand_chip")Cc Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- Oops, move check on the saveenv side in toerase_and_write_env
---
?common/env_nand.c | 9 +++++++--
?1 file changed, 7 insertions(+), 2 deletions(-)common/env_nand.c +0
-0@@ -163,6 +163,9 @@ static int erase_and_write_env(const struct env_location *location, ?{ ? int ret = 0;?
common/env_nand.c +3
-0+if (!nand_info[0 ]) +return 1 ; +?
printf("Erasing %s...\n", location->name);
? if (nand_erase_opts(nand_info[0], &location->erase_opts))
? return 1;common/env_nand.c +1
-1@@ -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;?
common/env_nand.c +3
-1- blocksize = nand_info[0 ]->erasesize; +if (nand_info[0 ]) + blocksize = nand_info[0 ]->erasesize; +
Quoted 8 lines
Quoted 3 lines
? if (!blocksize)
? return 1;
?Messing around with blocksize rather than directly returning is awkward -- it makes it look as if you could proceed with blocksize zero until you read the next statement. ?And is there ever a case where blocksize can be zero, now that uninitialized NAND devices will simply have a NULL pointer?
OK, I can see how that reads awkwardly now. And I suspect that no, blocksize could never be valid and zero. I'll re-work for a v3.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160815/90a93730/attachment.sig>