[U-Boot] [PATCH] squash build warning in cmd_sf.c

prabhakar.csengg at gmail.com prabhakar.csengg at gmail.com
Tue Oct 4 13:45:25 CEST 2011


From: Prabhakar Lad <prabhakar.csengg at gmail.com>

Fix build warning and returning early in case of failure

cmd_sf.c: In function 'do_spi_flash':
cmd_sf.c:164: warning: 'skipped' may be used uninitialized in this function
cmd_sf.c:164: note: 'skipped' was declared here

Signed-off-by: Prabhakar Lad <prabhakar.csengg at gmail.com>
---
 common/cmd_sf.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index c8c547a..bdf7915 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -164,21 +164,19 @@ static int spi_flash_update(struct spi_flash *flash, u32 offset,
 	size_t skipped;		/* statistics */
 
 	cmp_buf = malloc(flash->sector_size);
-	if (cmp_buf) {
-		for (skipped = 0; buf < end && !err_oper;
-				buf += todo, offset += todo) {
-			todo = min(end - buf, flash->sector_size);
-			err_oper = spi_flash_update_block(flash, offset, todo,
-					buf, cmp_buf, &skipped);
-		}
-	} else {
+	if (!cmp_buf) {
 		err_oper = "malloc";
-	}
-	free(cmp_buf);
-	if (err_oper) {
 		printf("SPI flash failed in %s step\n", err_oper);
 		return 1;
 	}
+
+	for (skipped = 0; buf < end && !err_oper;
+			buf += todo, offset += todo) {
+		todo = min(end - buf, flash->sector_size);
+		err_oper = spi_flash_update_block(flash, offset, todo,
+				buf, cmp_buf, &skipped);
+	}
+	free(cmp_buf);
 	printf("%zu bytes written, %zu bytes skipped\n", len - skipped,
 	       skipped);
 	return 0;
-- 
1.7.0.4



More information about the U-Boot mailing list