diff mbox series

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

Message ID 20241018083006.10349-5-b.spranger@linutronix.de
State New
Delegated to: Eugen Hristev
Headers show
Series collected fallout of porting an ATSAMA5D27 based board | expand

Commit Message

Benedikt Spranger Oct. 18, 2024, 8:30 a.m. UTC
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@linutronix.de>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/mtd/nand/raw/nand_base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

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