[PATCH 2/2] cmd: mtd: fix default length calculation when offset is specified

Peter Suti peter.suti at streamunlimited.com
Mon Jan 12 09:39:03 CET 2026


Hi Michael,

On 12/20/25 09:42, Michael Nazzareno Trimarchi wrote:
> On Tue, Dec 16, 2025 at 2:41 PM Peter Suti
> <peter.suti at streamunlimited.com> wrote:
>> ---
>>   cmd/mtd.c | 10 +++++++++-
>>   1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/cmd/mtd.c b/cmd/mtd.c
>> index 1d1845bce44..9f6e3226c15 100644
>> --- a/cmd/mtd.c
>> +++ b/cmd/mtd.c
>> @@ -519,7 +519,15 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
>>                  goto out_put_mtd;
>>          }
>>
>> -       default_len = dump ? mtd->writesize : mtd->size;
>> +       if (dump) {
>> +               default_len = mtd->writesize;
>> +       } else {
>> +               if (start_off < mtd->size)
>> +                       default_len = mtd->size - start_off;
>> +               else
>> +                       default_len = 0;
> Should it fail if the requested offset is bigger than mtd->size
>
> Michael

I think that would make more sense, yes. I'll send V2 with that fix.

Best Regards, Peter



More information about the U-Boot mailing list