mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Steffen Trumtrar <str@pengutronix.de>
Subject: [PATCH 1/3] mtd: initialize partitions_entry
Date: Thu, 12 Oct 2023 13:10:42 +0200	[thread overview]
Message-ID: <20231012111044.406987-1-s.hauer@pengutronix.de> (raw)

&mtd->partitions_entry is added to the parents partition list only when
DEVFS_PARTITION_FIXED is not set, but later this check is not done when
removing it from the list again. This results in NULL pointer derefs
when a mtd partition is added with DEVFS_PARTITION_FIXED set and removed
later.

Do a INIT_LIST_HEAD() on &mtd->partitions_entry so we can safely call
list_del() on it later without additional checks. This means we can
remove the existing check as well.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index ae6b0f9cd4..97a7996cf6 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -688,6 +688,7 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
 					     mtd->dev.id);
 
 	INIT_LIST_HEAD(&mtd->partitions);
+	INIT_LIST_HEAD(&mtd->partitions_entry);
 
 	mtd->cdev.priv = mtd;
 	mtd->cdev.dev = &mtd->dev;
@@ -763,8 +764,7 @@ int del_mtd_device(struct mtd_info *mtd)
 	unregister_device(&mtd->dev);
 	free(mtd->param_size.value);
 	free(mtd->cdev.name);
-	if (mtd->parent)
-		list_del(&mtd->partitions_entry);
+	list_del(&mtd->partitions_entry);
 
 	return 0;
 }
-- 
2.39.2




             reply	other threads:[~2023-10-12 11:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 11:10 Sascha Hauer [this message]
2023-10-12 11:10 ` [PATCH 2/3] bootstrap: Fix partition creation Sascha Hauer
2023-10-12 11:47   ` Steffen Trumtrar
2023-10-12 13:36     ` Sascha Hauer
2023-10-12 11:10 ` [PATCH 3/3] devfs: check for valid flags before removing a partition Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231012111044.406987-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=str@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox