Skip to contentSkip to conversation

mtd: core: fix NULL pointer dereference with mtd_check_of_node

PATCH New Christian Marangi 1 participant 1 message Jul 3, 2022

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

PATCH 1/1 mtd: core: fix NULL pointer dereference with mtd_check_of_node

Actually check if mtd dev have a parent to fix NULL pointer dereference kernel panic in mtd_check_of_node.

Fixes ad9b10d1eaad ("mtd: core: introduce of support for dynamic partitions")
---
 drivers/mtd/mtdcore.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/mtdcore.c +5 -1
index 6fafea80fd98..48a357fcf2ed 100644
@@ -558,8 +558,12 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 	if (dev_of_node(&mtd->dev))
 		return;
 
-	/* Check if a partitions node exist */
+	/* Make sure we have a parent */
 	parent = mtd->parent;
+	if (!parent)
+		return;
+
+	/* Check if a partitions node exist */
 	parent_dn = dev_of_node(&parent->dev);
 	if (!parent_dn)
 		return;
Signature · 1 line
2.36.1