[PATCH] mtd: nand: Prevent dereference of NULL pointer

Michael Nazzareno Trimarchi michael at amarulasolutions.com
Thu Aug 7 17:19:34 CEST 2025


Hi

On Thu, Aug 7, 2025 at 5:01 PM Andrew Goodbody <andrew.goodbody at linaro.org>
wrote:

> On 01/07/2025 17:12, Andrew Goodbody wrote:
> > In nand_wait_ready there is a loop that includes a NULL check for
> > chip->dev_ready before it is dereferenced. Use a NULL check once the
> > loop is exited as well to cover the case where it exits due to a timeout
> > and it is therefore not known if chip->dev_ready is NULL or not.
> >
> > This issue found by Smatch.
> >
> > Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> > ---
> >   drivers/mtd/nand/raw/nand_base.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/nand/raw/nand_base.c
> b/drivers/mtd/nand/raw/nand_base.c
> > index d3d1b93947b..48e3685d995 100644
> > --- a/drivers/mtd/nand/raw/nand_base.c
> > +++ b/drivers/mtd/nand/raw/nand_base.c
> > @@ -566,7 +566,7 @@ void nand_wait_ready(struct mtd_info *mtd)
> >                               break;
> >       }
> >
> > -     if (!chip->dev_ready(mtd))
> > +     if (!chip->dev_ready || !chip->dev_ready(mtd))
> >               pr_warn("timeout while waiting for chip to become
> ready\n");
> >   }
> >   EXPORT_SYMBOL_GPL(nand_wait_ready);
> >
> > ---
> > base-commit: 7027b445cc0bfb86204ecb1f1fe596f5895048d9
> > change-id: 20250701-mtd_nand_fixes-191e5a19932d
>
> Are there any comments about this patch please?
>
>
Reviewed-by: Michael Trimarchi <michael at amarulasolutions.com>

I will queue end of the week

Michael


> Thanks,
> Andrew
>


-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael at amarulasolutions.com
__________________________________

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


More information about the U-Boot mailing list