From d325d0df3ebbdb7989b1ea319ab71f71763f750c Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Thu, 3 Mar 2022 22:48:24 -0800 Subject: [PATCH] Minor cleanup --- utils/mqnic-fw.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/utils/mqnic-fw.c b/utils/mqnic-fw.c index 7a09bf482..bd5f6d328 100644 --- a/utils/mqnic-fw.c +++ b/utils/mqnic-fw.c @@ -133,7 +133,7 @@ static void usage(char *name) int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void *dest) { - int ret; + int ret = 0; size_t remain = len; size_t seg; int step = 0x10000; @@ -163,13 +163,15 @@ int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void seg = remain; } - printf("Read address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, ((100*(len-remain))/len)); + printf("Read address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, (100*(len-remain))/len); fflush(stdout); ret = flash_read(fdev, addr, seg, dest); - if (ret) - return ret; + if (ret) { + fprintf(stderr, "\nRead failed\n"); + goto err; + } addr += seg; remain -= seg; @@ -178,12 +180,13 @@ int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void printf("\n"); - return 0; +err: + return ret; } int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, const void *src) { - int ret; + int ret = 0; size_t remain = len; size_t seg; int step = 0x10000; @@ -215,13 +218,15 @@ int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, con seg = remain; } - printf("Write address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, ((100*(len-remain))/len)); + printf("Write address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, (100*(len-remain))/len); fflush(stdout); ret = flash_write(fdev, addr, seg, src); - if (ret) - return ret; + if (ret) { + fprintf(stderr, "\nWrite failed\n"); + goto err; + } addr += seg; remain -= seg; @@ -230,7 +235,8 @@ int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, con printf("\n"); - return 0; +err: + return ret; } int flash_erase_progress(struct flash_device *fdev, size_t addr, size_t len)