[PATCH 3/5] mtd: nand: raw: Fix potential NULL pointer dereference

Benedikt Spranger b.spranger at linutronix.de
Fri Oct 18 10:30:04 CEST 2024


A NAND manufacture ID may not be found in nand_manuf_ids[] database.
In case of an ONFI or JEDEC NAND a crutial NULL pointer check is missing
and printing out the manufacture name result in a NULL pointer
dereference. Instead of adding additional NULL pointer checks ensure
a valid nand_menufacture_desc and remove the checks entirely.

Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
Reviewed-by: John Ogness <john.ogness at linutronix.de>
---
 drivers/mtd/nand/raw/nand_base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 4401bdcdb90..5dbc47bfe5f 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4241,7 +4241,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip,
  * @id: manufacturer ID
  *
  * Returns a nand_manufacturer_desc object if the manufacturer is defined
- * in the NAND manufacturers database, NULL otherwise.
+ * in the NAND manufacturers database, "Unknown" entry otherwise.
  */
 static const struct nand_manufacturer *nand_get_manufacturer_desc(u8 id)
 {
@@ -4252,7 +4252,7 @@ static const struct nand_manufacturer *nand_get_manufacturer_desc(u8 id)
 			return &nand_manuf_ids[i];
 	}
 
-	return NULL;
+	return &nand_manuf_ids[i];
 }
 
 /*
@@ -4425,13 +4425,13 @@ ident_done:
 	else if (chip->jedec_version)
 		pr_info("%s %s\n", manufacturer_desc->name,
 			chip->jedec_params.model);
-	else if (manufacturer_desc)
+	else
 		pr_info("%s %s\n", manufacturer_desc->name, type->name);
 #else
 	if (chip->jedec_version)
 		pr_info("%s %s\n", manufacturer_desc->name,
 			chip->jedec_params.model);
-	else if (manufacturer_desc)
+	else
 		pr_info("%s %s\n", manufacturer_desc->name, type->name);
 #endif
 
-- 
2.45.2



More information about the U-Boot mailing list