mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] devfs: take into account for the partitions check that mtd is different
Date: Mon, 11 Jul 2022 11:09:14 +0200	[thread overview]
Message-ID: <20220711090915.1487105-1-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20220711083128.kwazqb2wbmqqvdub@pengutronix.de>

mtd partitions are separate devices. Their partition info is relative to
these subdevices and so offset is 0 for them. This needs to be taken
into account for the overlap check.

Fixes: 7f9f45b9bfef ("devfs: Do not create overlapping partitions")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 fs/devfs-core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 38423e5d1e07..dca5e10191d4 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -395,9 +395,20 @@ static bool region_overlap(loff_t starta, loff_t lena,
 static int check_overlap(struct cdev *cdev, const char *name, loff_t offset, loff_t size)
 {
 	struct cdev *cpart;
+	loff_t cpart_offset;
 
 	list_for_each_entry(cpart, &cdev->partitions, partition_entry) {
-		if (region_overlap(cpart->offset, cpart->size,
+		cpart_offset = cpart->offset;
+
+		/*
+		 * An mtd partition is represented by a separate cdev and its
+		 * cpart is relative to this one. So its .offset is 0 and we
+		 * have to consult .master_offset to get its offset.
+		 */
+		if (cpart->mtd)
+			cpart_offset = cpart->mtd->master_offset;
+
+		if (region_overlap(cpart_offset, cpart->size,
 				   offset, size))
 			goto conflict;
 	}
@@ -408,7 +419,7 @@ conflict:
 	pr_err("New partition %s (0x%08llx-0x%08llx) on %s "
 		"overlaps with partition %s (0x%08llx-0x%08llx), not creating it\n",
 		name, offset, offset + size - 1, cpart->name,
-		cpart->name, cpart->offset, cpart->offset + cpart->size - 1);
+		cpart->name, cpart_offset, cpart_offset + cpart->size - 1);
 
 	return -EINVAL;
 }
-- 
2.36.1




  reply	other threads:[~2022-07-11  9:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11  7:30 [PATCH] devfs: Do not create overlapping partitions Sascha Hauer
2022-07-11  8:31 ` Uwe Kleine-König
2022-07-11  9:09   ` Uwe Kleine-König [this message]
2022-07-11  9:09     ` [PATCH 2/2] devfs: Fix device name in overlap error message Uwe Kleine-König
2022-07-11 10:31     ` [PATCH 1/2] devfs: take into account for the partitions check that mtd is different 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=20220711090915.1487105-1-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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