Skip to contentSkip to conversation

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

PATCH Applied Ashok Reddy Soma 5 participants 7 messages May 16, 2023 – Jun 3, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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>

---

Changes in v3:
- Change printf to debug as it is too verbose

Changes in v2:
- Changed print from 'size is 0' to Invalid size 0 without quites.
- Modified description to be imperative
- Fixed typo in description from "samething" to "same thing"

 cmd/legacy-mtd-utils.c | 5 +++++
 cmd/sf.c               | 5 +++++
 2 files changed, 10 insertions(+)
cmd/legacy-mtd-utils.c +5 -0
index ac7139f84d..5903a90fe5 100644
@@ -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)
cmd/sf.c +5 -0
index 11b9c25896..55bef2f769 100644
@@ -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",
Signature · 1 line
2.17.1
Applied
#1 lore raw
Quoted 19 lines · Ashok Reddy Soma

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>

Quoted 3 lines

---

Applied it to my queue. If someone else wants to take please let me know and I will drop it from my queue.

Thanks,
Michal

#2 lore raw
Quoted 22 lines · Michal Simek
Quoted 19 lines · Ashok Reddy Soma

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>

Quoted 5 lines
Quoted 3 lines

---

Applied it to my queue. If someone else wants to take please let me know and I will drop it from my queue.

I believe Jagan should be picking SF patches ?

#3 lore raw
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Michal Simek
Quoted 21 lines · Ashok Reddy Soma

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>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

---

Applied it to my queue. If someone else wants to take please let me know and I will drop it from my queue.

I believe Jagan should be picking SF patches ?

Sorry, I missed this during a couple of travels last week.

Jagan.

#4 lore raw
Quoted 31 lines · Jagan Teki
Quoted 30 lines · Marek Vasut
Quoted 28 lines · Michal Simek
Quoted 24 lines · Ashok Reddy Soma

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>

---

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Applied it to my queue. If someone else wants to take please let me know and I will drop it from my queue.

I believe Jagan should be picking SF patches ?

Sorry, I missed this during a couple of travels last week.

Time to prepare a late MR against u-boot/next then ? I think there are also a few other patches pending .

#5 lore raw
Quoted 36 lines · Marek Vasut
Quoted 34 lines · Jagan Teki
Quoted 33 lines · Marek Vasut
Quoted 30 lines · Michal Simek
Quoted 21 lines · Ashok Reddy Soma

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>

Quoted 3 lines

---

Applied it to my queue. If someone else wants to take please let me know and I will drop it from my queue.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I believe Jagan should be picking SF patches ?

Sorry, I missed this during a couple of travels last week.

Time to prepare a late MR against u-boot/next then ? I think there are also a few other patches pending .

Yes, Will wind up all. thanks.

Jagan.

#6 lore raw
In reply to Ashok Reddy Soma
Quoted 19 lines · Ashok Reddy Soma

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>

Quoted 1 line

Applied to u-boot/next, thanks!

Signature · 1 line
Tom