diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2022-07-11 11:09:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-07-11 11:51:13 +0200 |
commit | 9d42c77f126eb394fe369797a49ada67e4495faf (patch) | |
tree | 623b4cdaf5fcf1731de18afe82c1d7a9b5f1b926 | |
parent | ae815e4e7159ed8edfc6ec9714cc6cb625edc802 (diff) | |
download | barebox-9d42c77f126eb394fe369797a49ada67e4495faf.tar.gz barebox-9d42c77f126eb394fe369797a49ada67e4495faf.tar.xz |
devfs: take into account for the partitions check that mtd is different
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>
Link: https://lore.barebox.org/20220711090915.1487105-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | fs/devfs-core.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 38423e5d1e..dca5e10191 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; } |