Message ID | 20231102113829.58852-1-dario.binacchi@amarulasolutions.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
On Thu, Nov 2, 2023 at 12:38 PM Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > > If the "mtd" parameter is NULL, the search will definitely yield a > negative result. In that case, it's better to exit immediately. > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > --- > > drivers/mtd/nand/raw/nand.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/nand.c b/drivers/mtd/nand/raw/nand.c > index eacd99c4e275..55c00ac815dd 100644 > --- a/drivers/mtd/nand/raw/nand.c > +++ b/drivers/mtd/nand/raw/nand.c > @@ -41,8 +41,11 @@ int nand_mtd_to_devnum(struct mtd_info *mtd) > { > int i; > > + if (!mtd) > + return -ENODEV; > + > for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { > - if (mtd && get_nand_dev_by_index(i) == mtd) > + if (get_nand_dev_by_index(i) == mtd) > return i; > } > > -- > 2.42.0 > Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
diff --git a/drivers/mtd/nand/raw/nand.c b/drivers/mtd/nand/raw/nand.c index eacd99c4e275..55c00ac815dd 100644 --- a/drivers/mtd/nand/raw/nand.c +++ b/drivers/mtd/nand/raw/nand.c @@ -41,8 +41,11 @@ int nand_mtd_to_devnum(struct mtd_info *mtd) { int i; + if (!mtd) + return -ENODEV; + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { - if (mtd && get_nand_dev_by_index(i) == mtd) + if (get_nand_dev_by_index(i) == mtd) return i; }
If the "mtd" parameter is NULL, the search will definitely yield a negative result. In that case, it's better to exit immediately. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> --- drivers/mtd/nand/raw/nand.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)