diff mbox series

cmd: sf/nand: Print and return failure when 0 length is passed

Message ID 20230412071348.8666-1-ashok.reddy.soma@amd.com
State Superseded
Delegated to: Dario Binacchi
Headers show
Series cmd: sf/nand: Print and return failure when 0 length is passed | expand

Commit Message

Ashok Reddy Soma April 12, 2023, 7:13 a.m. UTC
For sf commands, when '0' length is passed for erase, update, write or
read, we might see undesired results. Ideally '0' length means nothing to
do.

So print 'size is 0' and return cmd failure when length '0' is passed to sf
commands. Samething applies for nand commands also.

Example:

ZynqMP> sf erase 0 0
'size is 0'
ZynqMP> sf write 10000 0 0
'size is 0'
ZynqMP> sf read 10000 0 0
'size is 0'
ZynqMP> sf update 1000 10000 0
'size is 0'
ZynqMP>

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@amd.com>
---

 cmd/legacy-mtd-utils.c | 5 +++++
 cmd/sf.c               | 5 +++++
 2 files changed, 10 insertions(+)

Comments

Michal Simek April 12, 2023, 7:34 a.m. UTC | #1
On 4/12/23 09:13, Ashok Reddy Soma wrote:
> For sf commands, when '0' length is passed for erase, update, write or
> read, we might see undesired results. Ideally '0' length means nothing to

Use imperative mode.

> do.
> 
> So print 'size is 0' and return cmd failure when length '0' is passed to sf
> commands. Samething applies for nand commands also.

typo

> 
> Example:
> 
> ZynqMP> sf erase 0 0
> 'size is 0'

I don't think '' around is helping with anything.

I would even change the message to be more accurate.

what about just?
invalid size


Thanks,
Michal
diff mbox series

Patch

diff --git a/cmd/legacy-mtd-utils.c b/cmd/legacy-mtd-utils.c
index ac7139f84d..7b49bfd858 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) {
+		printf("'size is 0'\n");
+		return -1;
+	}
+
 print:
 	printf("device %d ", *idx);
 	if (*size == chipsize)
diff --git a/cmd/sf.c b/cmd/sf.c
index 11b9c25896..46b5475fe8 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) {
+		printf("'size is 0'\n");
+		return CMD_RET_FAILURE;
+	}
+
 	/* Consistency checking */
 	if (offset + size > flash->size) {
 		printf("ERROR: attempting %s past flash size (%#x)\n",