summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAshok Reddy Soma <ashok.reddy.soma@amd.com>2023-05-16 05:52:36 -0600
committerMichal Simek <michal.simek@amd.com>2023-06-12 13:24:31 +0200
commitf5aa35c932a073489b3996c26435d7e16a1d6428 (patch)
tree05aaf35bd8e07187deadbf3287798a19db7865ff /cmd
parentb4501aa0283d664dfa9d93ed56a8d1ce97f95b14 (diff)
downloadu-boot-f5aa35c932a073489b3996c26435d7e16a1d6428.tar.gz
u-boot-f5aa35c932a073489b3996c26435d7e16a1d6428.tar.bz2
u-boot-f5aa35c932a073489b3996c26435d7e16a1d6428.zip
cmd: sf/nand: Print and return failure when 0 length is passed
For sf commands, when '0' length is passed for erase, update, write or read, there might be undesired results. Ideally '0' length means nothing to do. So print 'ERROR: Invalid size 0' and return cmd failure when length '0' is passed to sf commands. Same thing applies for nand commands also. Example: ZynqMP> sf erase 0 0 ERROR: Invalid size 0 ZynqMP> sf write 10000 0 0 ERROR: Invalid size 0 ZynqMP> sf read 10000 0 0 ERROR: Invalid size 0 ZynqMP> sf update 1000 10000 0 ERROR: Invalid size 0 ZynqMP> Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@amd.com> Link: https://lore.kernel.org/r/20230516115236.22458-1-ashok.reddy.soma@amd.com Signed-off-by: Michal Simek <michal.simek@amd.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/legacy-mtd-utils.c5
-rw-r--r--cmd/sf.c5
2 files changed, 10 insertions, 0 deletions
diff --git a/cmd/legacy-mtd-utils.c b/cmd/legacy-mtd-utils.c
index ac7139f84d..5903a90fe5 100644
--- a/cmd/legacy-mtd-utils.c
+++ b/cmd/legacy-mtd-utils.c
@@ -88,6 +88,11 @@ int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
return -1;
}
+ if (*size == 0) {
+ debug("ERROR: Invalid size 0\n");
+ return -1;
+ }
+
print:
printf("device %d ", *idx);
if (*size == chipsize)
diff --git a/cmd/sf.c b/cmd/sf.c
index 11b9c25896..55bef2f769 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -353,6 +353,11 @@ static int do_spi_flash_erase(int argc, char *const argv[])
if (ret != 1)
return CMD_RET_USAGE;
+ if (size == 0) {
+ debug("ERROR: Invalid size 0\n");
+ return CMD_RET_FAILURE;
+ }
+
/* Consistency checking */
if (offset + size > flash->size) {
printf("ERROR: attempting %s past flash size (%#x)\n",