diff mbox series

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

Message ID 20230516115236.22458-1-ashok.reddy.soma@amd.com
State Accepted
Commit f5aa35c932a073489b3996c26435d7e16a1d6428
Delegated to: Tom Rini
Headers show
Series [v3] cmd: sf/nand: Print and return failure when 0 length is passed | expand

Commit Message

Ashok Reddy Soma May 16, 2023, 11:52 a.m. UTC
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>
---

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(+)

Comments

Michal Simek May 30, 2023, 12:23 p.m. UTC | #1
On 5/16/23 13:52, Ashok Reddy Soma wrote:
> 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>
> ---
> 

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
Marek Vasut May 30, 2023, 1:37 p.m. UTC | #2
On 5/30/23 14:23, Michal Simek wrote:
> 
> 
> On 5/16/23 13:52, Ashok Reddy Soma wrote:
>> 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>
>> ---
>>
> 
> 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 ?
Tom Rini June 1, 2023, 3:25 p.m. UTC | #3
On Tue, May 16, 2023 at 05:52:36AM -0600, Ashok Reddy Soma wrote:

> 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>

Applied to u-boot/next, thanks!
Jagan Teki June 2, 2023, 6:28 a.m. UTC | #4
On Tue, May 30, 2023 at 7:07 PM Marek Vasut <marex@denx.de> wrote:
>
> On 5/30/23 14:23, Michal Simek wrote:
> >
> >
> > On 5/16/23 13:52, Ashok Reddy Soma wrote:
> >> 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>
> >> ---
> >>
> >
> > 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.
Marek Vasut June 2, 2023, 6:32 a.m. UTC | #5
On 6/2/23 08:28, Jagan Teki wrote:
> On Tue, May 30, 2023 at 7:07 PM Marek Vasut <marex@denx.de> wrote:
>>
>> On 5/30/23 14:23, Michal Simek wrote:
>>>
>>>
>>> On 5/16/23 13:52, Ashok Reddy Soma wrote:
>>>> 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>
>>>> ---
>>>>
>>>
>>> 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 .
Jagan Teki June 3, 2023, 4:10 a.m. UTC | #6
On Fri, Jun 2, 2023 at 12:03 PM Marek Vasut <marex@denx.de> wrote:
>
> On 6/2/23 08:28, Jagan Teki wrote:
> > On Tue, May 30, 2023 at 7:07 PM Marek Vasut <marex@denx.de> wrote:
> >>
> >> On 5/30/23 14:23, Michal Simek wrote:
> >>>
> >>>
> >>> On 5/16/23 13:52, Ashok Reddy Soma wrote:
> >>>> 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>
> >>>> ---
> >>>>
> >>>
> >>> 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 .

Yes, Will wind up all. thanks.

Jagan.
diff mbox series

Patch

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",