Re: [PATCH] cmd: sf: Fix sf probe crash

2024-04-14 Thread Dario Binacchi
Hi Weizhao,

On Fri, Mar 15, 2024 at 7:07 PM Jonas Karlman  wrote:
>
> Hi,
>
> On 2024-01-04 12:46, Weizhao Ouyang wrote:
> > Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> > crashes.
> >
> > Signed-off-by: Weizhao Ouyang 
>
> This fixes a null pointer dereference when running "sf probe" and there
> are no spi devices enabled in the device tree for my boards, so:
>
> Fixes: 3feea0ba196a ("spi: spi_flash_probe_bus_cs() rely on DT for spi speed 
> and mode")
>
> Reviewed-by: Jonas Karlman 
>
> Regards,
> Jonas
>
> > ---
> >  cmd/sf.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/cmd/sf.c b/cmd/sf.c
> > index 730996c02b..e3866899f6 100644
> > --- a/cmd/sf.c
> > +++ b/cmd/sf.c
> > @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> > argv[])
> >   }
> >   flash = NULL;
> >   if (use_dt) {
> > - spi_flash_probe_bus_cs(bus, cs, );
> > - flash = dev_get_uclass_priv(new);
> > + ret = spi_flash_probe_bus_cs(bus, cs, );
> > + if (!ret)
> > + flash = dev_get_uclass_priv(new);
> >   } else {
> >   flash = spi_flash_probe(bus, cs, speed, mode);
> >   }
>

Applied to nand-next

Thanks and regards
Dario
-- 

Dario Binacchi

Senior Embedded Linux Developer

dario.binac...@amarulasolutions.com

__


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
i...@amarulasolutions.com

www.amarulasolutions.com


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-03-15 Thread Jonas Karlman
Hi,

On 2024-01-04 12:46, Weizhao Ouyang wrote:
> Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> crashes.
> 
> Signed-off-by: Weizhao Ouyang 

This fixes a null pointer dereference when running "sf probe" and there
are no spi devices enabled in the device tree for my boards, so:

Fixes: 3feea0ba196a ("spi: spi_flash_probe_bus_cs() rely on DT for spi speed 
and mode")

Reviewed-by: Jonas Karlman 

Regards,
Jonas

> ---
>  cmd/sf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/sf.c b/cmd/sf.c
> index 730996c02b..e3866899f6 100644
> --- a/cmd/sf.c
> +++ b/cmd/sf.c
> @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> argv[])
>   }
>   flash = NULL;
>   if (use_dt) {
> - spi_flash_probe_bus_cs(bus, cs, );
> - flash = dev_get_uclass_priv(new);
> + ret = spi_flash_probe_bus_cs(bus, cs, );
> + if (!ret)
> + flash = dev_get_uclass_priv(new);
>   } else {
>   flash = spi_flash_probe(bus, cs, speed, mode);
>   }



Re: [PATCH] cmd: sf: Fix sf probe crash

2024-03-04 Thread Michael Nazzareno Trimarchi
Hi

On Mon, Mar 4, 2024 at 4:44 PM Heinrich Schuchardt  wrote:
>
> On 04.03.24 15:47, Weizhao Ouyang wrote:
> > Gentle ping. Not merged yet.
> >
> > BR,
> > Weizhao
>
> Hello Dario,
>
> that patch is in your patchwork review queue. Could you, please, have a
> look.

He is with me, I will ping about all the patches that we need to queue

Michael

>
> Best regards
>
> Heinrich
>
> >
> > On Thu, Jan 4, 2024 at 7:46 PM Weizhao Ouyang  wrote:
> >>
> >> Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> >> crashes.
> >>
> >> Signed-off-by: Weizhao Ouyang 
> >> ---
> >>   cmd/sf.c | 5 +++--
> >>   1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/cmd/sf.c b/cmd/sf.c
> >> index 730996c02b..e3866899f6 100644
> >> --- a/cmd/sf.c
> >> +++ b/cmd/sf.c
> >> @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> >> argv[])
> >>  }
> >>  flash = NULL;
> >>  if (use_dt) {
> >> -   spi_flash_probe_bus_cs(bus, cs, );
> >> -   flash = dev_get_uclass_priv(new);
> >> +   ret = spi_flash_probe_bus_cs(bus, cs, );
> >> +   if (!ret)
> >> +   flash = dev_get_uclass_priv(new);
> >>  } else {
> >>  flash = spi_flash_probe(bus, cs, speed, mode);
> >>  }
> >> --
> >> 2.39.2
> >>
>


-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-03-04 Thread Heinrich Schuchardt

On 04.03.24 15:47, Weizhao Ouyang wrote:

Gentle ping. Not merged yet.

BR,
Weizhao


Hello Dario,

that patch is in your patchwork review queue. Could you, please, have a
look.

Best regards

Heinrich



On Thu, Jan 4, 2024 at 7:46 PM Weizhao Ouyang  wrote:


Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
crashes.

Signed-off-by: Weizhao Ouyang 
---
  cmd/sf.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 730996c02b..e3866899f6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const argv[])
 }
 flash = NULL;
 if (use_dt) {
-   spi_flash_probe_bus_cs(bus, cs, );
-   flash = dev_get_uclass_priv(new);
+   ret = spi_flash_probe_bus_cs(bus, cs, );
+   if (!ret)
+   flash = dev_get_uclass_priv(new);
 } else {
 flash = spi_flash_probe(bus, cs, speed, mode);
 }
--
2.39.2





Re: [PATCH] cmd: sf: Fix sf probe crash

2024-03-04 Thread Weizhao Ouyang
Gentle ping. Not merged yet.

BR,
Weizhao

On Thu, Jan 4, 2024 at 7:46 PM Weizhao Ouyang  wrote:
>
> Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> crashes.
>
> Signed-off-by: Weizhao Ouyang 
> ---
>  cmd/sf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cmd/sf.c b/cmd/sf.c
> index 730996c02b..e3866899f6 100644
> --- a/cmd/sf.c
> +++ b/cmd/sf.c
> @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> argv[])
> }
> flash = NULL;
> if (use_dt) {
> -   spi_flash_probe_bus_cs(bus, cs, );
> -   flash = dev_get_uclass_priv(new);
> +   ret = spi_flash_probe_bus_cs(bus, cs, );
> +   if (!ret)
> +   flash = dev_get_uclass_priv(new);
> } else {
> flash = spi_flash_probe(bus, cs, speed, mode);
> }
> --
> 2.39.2
>


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michal Simek




On 1/4/24 13:28, Weizhao Ouyang wrote:

On Thu, Jan 4, 2024 at 8:21 PM Michal Simek  wrote:




On 1/4/24 13:15, Weizhao Ouyang wrote:

On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:




On 1/4/24 12:46, Weizhao Ouyang wrote:

Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
crashes.

Signed-off-by: Weizhao Ouyang 
---
cmd/sf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 730996c02b..e3866899f6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const argv[])
}
flash = NULL;
if (use_dt) {
- spi_flash_probe_bus_cs(bus, cs, );
- flash = dev_get_uclass_priv(new);
+ ret = spi_flash_probe_bus_cs(bus, cs, );


if (ret)
  return ret;

don't you want to rather propagate that error?



Well, since the spi_flash is empty, the following code will
print the error message and return.


And you return 0 which means everything is fine. But is everything fine in this
case? Or do you want to see the error?

This is command it means you can simply use && and if previous command succeed
you can call something else.



Hi Michal,

Please check the code that follows this commit snippet:

if (!flash) {
 printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
 bus, cs, ret);
 return 1;
}

it will print the error and return 1 as the return value.


ok. Then good.

Acked-by: Michal Simek 

Thanks,
Michal


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michael Nazzareno Trimarchi
Hi

On Thu, Jan 4, 2024 at 1:40 PM Weizhao Ouyang  wrote:
>
> On Thu, Jan 4, 2024 at 8:29 PM Michael Nazzareno Trimarchi
>  wrote:
> >
> > Hi
> >
> > On Thu, Jan 4, 2024 at 1:16 PM Weizhao Ouyang  wrote:
> > >
> > > On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:
> > > >
> > > >
> > > >
> > > > On 1/4/24 12:46, Weizhao Ouyang wrote:
> > > > > Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> > > > > crashes.
> > > > >
> > > > > Signed-off-by: Weizhao Ouyang 
> > > > > ---
> > > > >   cmd/sf.c | 5 +++--
> > > > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/cmd/sf.c b/cmd/sf.c
> > > > > index 730996c02b..e3866899f6 100644
> > > > > --- a/cmd/sf.c
> > > > > +++ b/cmd/sf.c
> > > > > @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char 
> > > > > *const argv[])
> > > > >   }
> > > > >   flash = NULL;
> > > > >   if (use_dt) {
> > > > > - spi_flash_probe_bus_cs(bus, cs, );
> > > > > - flash = dev_get_uclass_priv(new);
> > > > > + ret = spi_flash_probe_bus_cs(bus, cs, );
> > > >
> > > > if (ret)
> > > > return ret;
> > > >
> > > > don't you want to rather propagate that error?
> > > >
> > >
> > > Well, since the spi_flash is empty, the following code will
> > > print the error message and return.
> > >
> >
> > flash = NULL;
> >
> >   if (!flash) {
> > printf("Failed to initialize SPI flash at %u:%u (error 
> > %d)\n",
> >bus, cs, ret);
> > return 1;
> >   }
> >
> > This code does not change error handling that is already present here.
>
> Hi Michael,
>
> Sorry I didn't get your point. This patch is designed to avoid
> spi_flash_probe_bus_cs() crash by null pointer, and let the
> current existing error handling to prompt it. So I'm not
> trying to change the current error handling.
>

I have said exactly the same so I agree with you.

Michael

> BR,
> Weizhao
>
> > Michael
> >
> > > BR,
> > > Weizhao
> >
> >
> >
> > --
> > Michael Nazzareno Trimarchi
> > Co-Founder & Chief Executive Officer
> > M. +39 347 913 2170
> > mich...@amarulasolutions.com
> > __
> >
> > Amarula Solutions BV
> > Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> > T. +31 (0)85 111 9172
> > i...@amarulasolutions.com
> > www.amarulasolutions.com



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Weizhao Ouyang
On Thu, Jan 4, 2024 at 8:29 PM Michael Nazzareno Trimarchi
 wrote:
>
> Hi
>
> On Thu, Jan 4, 2024 at 1:16 PM Weizhao Ouyang  wrote:
> >
> > On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:
> > >
> > >
> > >
> > > On 1/4/24 12:46, Weizhao Ouyang wrote:
> > > > Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> > > > crashes.
> > > >
> > > > Signed-off-by: Weizhao Ouyang 
> > > > ---
> > > >   cmd/sf.c | 5 +++--
> > > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/cmd/sf.c b/cmd/sf.c
> > > > index 730996c02b..e3866899f6 100644
> > > > --- a/cmd/sf.c
> > > > +++ b/cmd/sf.c
> > > > @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> > > > argv[])
> > > >   }
> > > >   flash = NULL;
> > > >   if (use_dt) {
> > > > - spi_flash_probe_bus_cs(bus, cs, );
> > > > - flash = dev_get_uclass_priv(new);
> > > > + ret = spi_flash_probe_bus_cs(bus, cs, );
> > >
> > > if (ret)
> > > return ret;
> > >
> > > don't you want to rather propagate that error?
> > >
> >
> > Well, since the spi_flash is empty, the following code will
> > print the error message and return.
> >
>
> flash = NULL;
>
>   if (!flash) {
> printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
>bus, cs, ret);
> return 1;
>   }
>
> This code does not change error handling that is already present here.

Hi Michael,

Sorry I didn't get your point. This patch is designed to avoid
spi_flash_probe_bus_cs() crash by null pointer, and let the
current existing error handling to prompt it. So I'm not
trying to change the current error handling.

BR,
Weizhao

> Michael
>
> > BR,
> > Weizhao
>
>
>
> --
> Michael Nazzareno Trimarchi
> Co-Founder & Chief Executive Officer
> M. +39 347 913 2170
> mich...@amarulasolutions.com
> __
>
> Amarula Solutions BV
> Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> T. +31 (0)85 111 9172
> i...@amarulasolutions.com
> www.amarulasolutions.com


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michael Nazzareno Trimarchi
Hi

On Thu, Jan 4, 2024 at 1:16 PM Weizhao Ouyang  wrote:
>
> On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:
> >
> >
> >
> > On 1/4/24 12:46, Weizhao Ouyang wrote:
> > > Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> > > crashes.
> > >
> > > Signed-off-by: Weizhao Ouyang 
> > > ---
> > >   cmd/sf.c | 5 +++--
> > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/cmd/sf.c b/cmd/sf.c
> > > index 730996c02b..e3866899f6 100644
> > > --- a/cmd/sf.c
> > > +++ b/cmd/sf.c
> > > @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> > > argv[])
> > >   }
> > >   flash = NULL;
> > >   if (use_dt) {
> > > - spi_flash_probe_bus_cs(bus, cs, );
> > > - flash = dev_get_uclass_priv(new);
> > > + ret = spi_flash_probe_bus_cs(bus, cs, );
> >
> > if (ret)
> > return ret;
> >
> > don't you want to rather propagate that error?
> >
>
> Well, since the spi_flash is empty, the following code will
> print the error message and return.
>

flash = NULL;

  if (!flash) {
printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
   bus, cs, ret);
return 1;
  }

This code does not change error handling that is already present here.

Michael

> BR,
> Weizhao



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Weizhao Ouyang
On Thu, Jan 4, 2024 at 8:21 PM Michal Simek  wrote:
>
>
>
> On 1/4/24 13:15, Weizhao Ouyang wrote:
> > On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:
> >>
> >>
> >>
> >> On 1/4/24 12:46, Weizhao Ouyang wrote:
> >>> Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> >>> crashes.
> >>>
> >>> Signed-off-by: Weizhao Ouyang 
> >>> ---
> >>>cmd/sf.c | 5 +++--
> >>>1 file changed, 3 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/cmd/sf.c b/cmd/sf.c
> >>> index 730996c02b..e3866899f6 100644
> >>> --- a/cmd/sf.c
> >>> +++ b/cmd/sf.c
> >>> @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> >>> argv[])
> >>>}
> >>>flash = NULL;
> >>>if (use_dt) {
> >>> - spi_flash_probe_bus_cs(bus, cs, );
> >>> - flash = dev_get_uclass_priv(new);
> >>> + ret = spi_flash_probe_bus_cs(bus, cs, );
> >>
> >> if (ret)
> >>  return ret;
> >>
> >> don't you want to rather propagate that error?
> >>
> >
> > Well, since the spi_flash is empty, the following code will
> > print the error message and return.
>
> And you return 0 which means everything is fine. But is everything fine in 
> this
> case? Or do you want to see the error?
>
> This is command it means you can simply use && and if previous command succeed
> you can call something else.
>

Hi Michal,

Please check the code that follows this commit snippet:

if (!flash) {
printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
bus, cs, ret);
return 1;
}

it will print the error and return 1 as the return value.

BR,
Weizhao


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michal Simek




On 1/4/24 13:15, Weizhao Ouyang wrote:

On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:




On 1/4/24 12:46, Weizhao Ouyang wrote:

Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
crashes.

Signed-off-by: Weizhao Ouyang 
---
   cmd/sf.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 730996c02b..e3866899f6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const argv[])
   }
   flash = NULL;
   if (use_dt) {
- spi_flash_probe_bus_cs(bus, cs, );
- flash = dev_get_uclass_priv(new);
+ ret = spi_flash_probe_bus_cs(bus, cs, );


if (ret)
 return ret;

don't you want to rather propagate that error?



Well, since the spi_flash is empty, the following code will
print the error message and return.


And you return 0 which means everything is fine. But is everything fine in this 
case? Or do you want to see the error?


This is command it means you can simply use && and if previous command succeed 
you can call something else.


Thanks,
Michal




Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Weizhao Ouyang
On Thu, Jan 4, 2024 at 8:00 PM Michal Simek  wrote:
>
>
>
> On 1/4/24 12:46, Weizhao Ouyang wrote:
> > Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> > crashes.
> >
> > Signed-off-by: Weizhao Ouyang 
> > ---
> >   cmd/sf.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/cmd/sf.c b/cmd/sf.c
> > index 730996c02b..e3866899f6 100644
> > --- a/cmd/sf.c
> > +++ b/cmd/sf.c
> > @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> > argv[])
> >   }
> >   flash = NULL;
> >   if (use_dt) {
> > - spi_flash_probe_bus_cs(bus, cs, );
> > - flash = dev_get_uclass_priv(new);
> > + ret = spi_flash_probe_bus_cs(bus, cs, );
>
> if (ret)
> return ret;
>
> don't you want to rather propagate that error?
>

Well, since the spi_flash is empty, the following code will
print the error message and return.

BR,
Weizhao


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michal Simek




On 1/4/24 12:46, Weizhao Ouyang wrote:

Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
crashes.

Signed-off-by: Weizhao Ouyang 
---
  cmd/sf.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 730996c02b..e3866899f6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const argv[])
}
flash = NULL;
if (use_dt) {
-   spi_flash_probe_bus_cs(bus, cs, );
-   flash = dev_get_uclass_priv(new);
+   ret = spi_flash_probe_bus_cs(bus, cs, );


if (ret)
return ret;

don't you want to rather propagate that error?


Thanks,
Michal


Re: [PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Michael Nazzareno Trimarchi
Hi

On Thu, Jan 4, 2024 at 12:46 PM Weizhao Ouyang  wrote:
>
> Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
> crashes.
>
> Signed-off-by: Weizhao Ouyang 
> ---
>  cmd/sf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cmd/sf.c b/cmd/sf.c
> index 730996c02b..e3866899f6 100644
> --- a/cmd/sf.c
> +++ b/cmd/sf.c
> @@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const 
> argv[])
> }
> flash = NULL;
> if (use_dt) {
> -   spi_flash_probe_bus_cs(bus, cs, );
> -   flash = dev_get_uclass_priv(new);
> +   ret = spi_flash_probe_bus_cs(bus, cs, );
> +   if (!ret)
> +   flash = dev_get_uclass_priv(new);
> } else {
> flash = spi_flash_probe(bus, cs, speed, mode);
> }
> --
> 2.39.2
>

Reviewed-by: Michael Trimarchi 

Suggest to add documentation of spi_flash_probe_bus_cs in a separated patch

Michael


[PATCH] cmd: sf: Fix sf probe crash

2024-01-04 Thread Weizhao Ouyang
Handle the return value of spi_flash_probe_bus_cs() to avoid sf probe
crashes.

Signed-off-by: Weizhao Ouyang 
---
 cmd/sf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 730996c02b..e3866899f6 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -135,8 +135,9 @@ static int do_spi_flash_probe(int argc, char *const argv[])
}
flash = NULL;
if (use_dt) {
-   spi_flash_probe_bus_cs(bus, cs, );
-   flash = dev_get_uclass_priv(new);
+   ret = spi_flash_probe_bus_cs(bus, cs, );
+   if (!ret)
+   flash = dev_get_uclass_priv(new);
} else {
flash = spi_flash_probe(bus, cs, speed, mode);
}
-- 
2.39.2