Patchwork [U-Boot,4/4] common/env_nand.c: calculate crc only when readenv was OK

login
register
mail settings
Submitter Phil Sutter
Date Nov. 21, 2012, 12:59 p.m.
Message ID <1353502761-12640-4-git-send-email-phil.sutter@viprinet.com>
Download mbox | patch
Permalink /patch/200772/
State Not Applicable
Delegated to: Scott Wood
Headers show

Comments

Phil Sutter - Nov. 21, 2012, 12:59 p.m.
Calculating the checksum of incompletely read data is useless.

Signed-off-by: Phil Sutter <phil.sutter@viprinet.com>
---
 common/env_nand.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Patch

diff --git a/common/env_nand.c b/common/env_nand.c
index 58ba558..038aa00 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -333,8 +333,8 @@  void env_relocate_spec(void)
 	if (read1_fail && read2_fail)
 		puts("No Valid Environment Area found\n");
 
-	crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc;
-	crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc;
+	crc1_ok = !read1_fail && (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
+	crc2_ok = !read2_fail && (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
 
 	if (!crc1_ok && !crc2_ok) {
 		set_default_env("!bad CRC");