]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: nand: check nand_mtd_to_devnum() argument
authorDario Binacchi <dario.binacchi@amarulasolutions.com>
Thu, 2 Nov 2023 11:38:22 +0000 (12:38 +0100)
committerDario Binacchi <dario.binacchi@amarulasolutions.com>
Mon, 15 Jan 2024 07:58:24 +0000 (08:58 +0100)
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>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
Link: https://lore.kernel.org/all/20231102113829.58852-1-dario.binacchi@amarulasolutions.com
drivers/mtd/nand/raw/nand.c

index c1a0ebe6486a55b5e7734319d5947ff08bd542f3..b591170346d04722c22c77a6131f9e5be77ef47b 100644 (file)
@@ -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;
        }