Skip to contentSkip to conversation

mtd: nand: check nand_mtd_to_devnum() argument

PATCH In review Dario Binacchi 2 participants 2 messages Nov 2, 2023 – Nov 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: check nand_mtd_to_devnum() argument

If the "mtd" parameter is NULL, the search will definitely yield a negative result. In that case, it's better to exit immediately.

---

 drivers/mtd/nand/raw/nand.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/nand.c +4 -1
index eacd99c4e275..55c00ac815dd 100644
@@ -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;
 	}
 
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Dario Binacchi

If the "mtd" parameter is NULL, the search will definitely yield a negative result. In that case, it's better to exit immediately.

---

 drivers/mtd/nand/raw/nand.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/nand.c +4 -2
index eacd99c4e275..55c00ac815dd 100644
@@ -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;
        }
 
--
Quoted 2 lines

2.42.0

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

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