[PATCH] devfs: be more lax with partition boundaries

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu May 7 01:45:45 PDT 2015


If a partition starts inside its parent device but is too big such that
it extends over the device boundary, just chop it to the device's end.

This matches the behaviour of Linux.

The motivation for this change is that it makes it possible in some
cases to have the partitioning in a device tree fixed and still allow
different flash sizes.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 fs/devfs-core.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index f45f8cadf1b0..d456ebccaf06 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -290,12 +290,20 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev,
 
 	*end = offset + size;
 
-	if (offset < 0 || *end > cdev->size) {
-		pr_warn("partition %s not completely inside device %s\n",
-				partinfo->name, cdev->name);
+	if (offset < 0 || offset > cdev->size) {
+		pr_warn("start of partition %s not inside of device %s\n",
+			partinfo->name, cdev->name);
 		return ERR_PTR(-EINVAL);
 	}
 
+	if (*end > cdev->size) {
+		pr_warn("end of partition %s after end of device %s, chopping\n",
+			partinfo->name, cdev->name);
+
+		*end = cdev->size;
+		size = *end - offset;
+	}
+
 	if (IS_ENABLED(CONFIG_MTD) && cdev->mtd) {
 		struct mtd_info *mtd;
 
-- 
2.1.4




More information about the barebox mailing list