[U-Boot] [PATCH 3/4] env_sf: re-order error handling in single-buffer env_relocate_spec

Andreas Fenkart andreas.fenkart at digitalstrom.com
Mon Nov 28 11:01:16 CET 2016


this makes it easier comparable to the double-buffered version

Signed-off-by: Andreas Fenkart <andreas.fenkart at digitalstrom.com>
---
 common/env_sf.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/common/env_sf.c b/common/env_sf.c
index ba9ac8a..8a3de63 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -312,29 +312,31 @@ void env_relocate_spec(void)
 	char *buf = NULL;
 
 	buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
-
-	ret = setup_flash_device();
-	if (ret) {
-		if (buf)
-			free(buf);
+	if (!buf) {
+		set_default_env("!malloc() failed");
 		return;
 	}
 
+	ret = setup_flash_device();
+	if (ret)
+		goto out;
+
 	ret = spi_flash_read(env_flash,
 		CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
 	if (ret) {
 		set_default_env("!spi_flash_read() failed");
-		goto out;
+		goto err_read;
 	}
 
 	ret = env_import(buf, 1);
 	if (ret)
 		gd->env_valid = 1;
-out:
+
+err_read:
 	spi_flash_free(env_flash);
-	if (buf)
-		free(buf);
 	env_flash = NULL;
+out:
+	free(buf);
 }
 #endif
 
-- 
2.10.1



More information about the U-Boot mailing list