linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: core: fix NULL pointer dereference with mtd_check_of_node
@ 2022-07-03  9:56 Christian Marangi
  0 siblings, 0 replies; only message in thread
From: Christian Marangi @ 2022-07-03  9:56 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Christian Marangi, linux-mtd, linux-kernel
  Cc: kernel test robot, stable

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

Reported-by: kernel test robot <oliver.sang@intel.com>
Fixes: ad9b10d1eaad ("mtd: core: introduce of support for dynamic partitions")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/mtd/mtdcore.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 6fafea80fd98..48a357fcf2ed 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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;
-- 
2.36.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-03  9:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-03  9:56 [PATCH] mtd: core: fix NULL pointer dereference with mtd_check_of_node Christian Marangi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).