diff mbox

[U-Boot,v2,1/4] tools/env: return with error if redundant environments have unequal size

Message ID 1468681575-19671-2-git-send-email-andreas.fenkart@digitalstrom.com
State Deferred
Delegated to: Tom Rini
Headers show

Commit Message

Andreas Fenkart July 16, 2016, 3:06 p.m. UTC
For double buffering to work, the target buffer must always be big
enough to hold all data. This can only be ensured if buffers are of
equal size, otherwise one must be smaller and we risk data loss
when copying from the bigger to the smaller buffer.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
---
 tools/env/fw_env.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

Tom Rini July 23, 2016, 12:10 a.m. UTC | #1
On Sat, Jul 16, 2016 at 05:06:12PM +0200, Andreas Fenkart wrote:

> For double buffering to work, the target buffer must always be big
> enough to hold all data. This can only be ensured if buffers are of
> equal size, otherwise one must be smaller and we risk data loss
> when copying from the bigger to the smaller buffer.
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>

With https://patchwork.ozlabs.org/patch/648142/ applied this needs to be
reworked, and may not be applicable now, thanks!
diff mbox

Patch

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 692abda..b1c8217 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1382,18 +1382,19 @@  static int parse_config(struct env_opts *opts)
 		return -1;
 	}
 
-	if (HaveRedundEnv && stat (DEVNAME (1), &st)) {
-		fprintf (stderr,
-			"Cannot access MTD device %s: %s\n",
-			DEVNAME (1), strerror (errno));
-		return -1;
-	}
+	if (HaveRedundEnv) {
+		if (stat(DEVNAME(1), &st)) {
+			fprintf(stderr,
+				"Cannot access MTD device %s: %s\n",
+				DEVNAME(1), strerror(errno));
+			return -1;
+		}
 
-	if (HaveRedundEnv && ENVSIZE(0) != ENVSIZE(1)) {
-		ENVSIZE(0) = ENVSIZE(1) = min(ENVSIZE(0), ENVSIZE(1));
-		fprintf(stderr,
-			"Redundant environments have inequal size, set to 0x%08lx\n",
-			ENVSIZE(1));
+		if (ENVSIZE(0) != ENVSIZE(1)) {
+			fprintf(stderr,
+				"Redundant environments have unequal size");
+			return -1;
+		}
 	}
 
 	usable_envsize = CUR_ENVSIZE - sizeof(uint32_t);