From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP
Date: Sun, 16 Feb 2025 16:07:17 +0100 [thread overview]
Message-ID: <20250216150718.2348520-1-a.fatoum@pengutronix.de> (raw)
When a partition is created that's exactly the same size and offset as
an existing partition, barebox will create the new partition as link to
the existing partition.
Maintain this behavior, even if DEVFS_PARTITION_CAN_OVERLAP is set.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 133fd9ec026a..c9313ed73167 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -440,7 +440,7 @@ int devfs_remove(struct cdev *cdev)
/**
* check_overlap() - check overlap with existing partitions
* @cdev: parent cdev
- * @name: partition name for informational purposes on conflict
+ * @partinfo: partition information
* @offset: offset of new partition to be added
* @size: size of new partition to be added
*
@@ -448,7 +448,9 @@ int devfs_remove(struct cdev *cdev)
* partition if and only if it's identical in offset and size
* to an existing partition. Otherwise, PTR_ERR(-EINVAL).
*/
-static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t offset, loff_t size)
+static struct cdev *check_overlap(struct cdev *cdev,
+ const struct devfs_partition *partinfo,
+ loff_t offset, loff_t size)
{
struct cdev *cpart;
loff_t cpart_offset;
@@ -471,6 +473,8 @@ static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t of
}
if (region_overlap_size(cpart_offset, cpart->size, offset, size)) {
+ if (partinfo->flags & DEVFS_PARTITION_CAN_OVERLAP)
+ return NULL;
ret = -EINVAL;
goto conflict;
}
@@ -483,7 +487,7 @@ static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t of
__pr_printk(ret ? MSG_WARNING : MSG_DEBUG,
"New partition %s (0x%08llx-0x%08llx) on %s "
"%s with partition %s (0x%08llx-0x%08llx), not creating it\n",
- name, offset, offset + size - 1, cdev->name,
+ partinfo->name, offset, offset + size - 1, cdev->name,
ret ? "conflicts" : "identical",
cpart->name, cpart_offset, cpart_offset + cpart->size - 1);
@@ -530,16 +534,14 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev,
return ERR_PTR(-EINVAL);
}
- if (!(partinfo->flags & DEVFS_PARTITION_CAN_OVERLAP)) {
- overlap = check_overlap(cdev, partinfo->name, offset, size);
- if (overlap) {
- if (!IS_ERR(overlap)) {
- /* only fails with -EEXIST, which is fine */
- (void)devfs_create_link(overlap, partinfo->name);
- }
-
- return overlap;
+ overlap = check_overlap(cdev, partinfo, offset, size);
+ if (overlap) {
+ if (!IS_ERR(overlap)) {
+ /* only fails with -EEXIST, which is fine */
+ (void)devfs_create_link(overlap, partinfo->name);
}
+
+ return overlap;
}
/* Filter flags that we want to pass along to children */
--
2.39.5
next reply other threads:[~2025-02-16 15:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-16 15:07 Ahmad Fatoum [this message]
2025-02-16 15:07 ` [PATCH 2/2] cmdlinepart: refuse partitions with empty name Ahmad Fatoum
2025-02-17 7:36 ` [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP 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=20250216150718.2348520-1-a.fatoum@pengutronix.de \
--to=a.fatoum@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