[PATCH v2 1/3] mtdpart: Allow adding a partition of a partition

Dan Ehrenberg dehrenberg at chromium.org
Tue Feb 10 14:58:56 PST 2015


MTD allows dynamic partitioning by the BLKPG ioctl.
The current code restricts partition dynamic addition to work only on
the master MTD device. This doesn't make a lot of sense, and is
impossible to meet if the device is already partitioned (since the
master MTD device is not visible). This commit removes the restriction.

Signed-off-by: Dan Ehrenberg <dehrenberg at chromium.org>
---
 drivers/mtd/mtdchar.c | 4 ----
 drivers/mtd/mtdpart.c | 6 ++++++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5356395..30215c7 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -545,10 +545,6 @@ static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
 	switch (a.op) {
 	case BLKPG_ADD_PARTITION:
 
-		/* Only master mtd device must be used to add partitions */
-		if (mtd_is_partition(mtd))
-			return -EINVAL;
-
 		/* Sanitize user input */
 		p.devname[BLKPG_DEVNAMELTH - 1] = '\0';
 
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a3e3a7d..7c6f526 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -566,6 +566,12 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 	if (length <= 0)
 		return -EINVAL;
 
+	if (mtd_is_partition(master)) {
+		struct mtd_part *master_partition = PART(master);
+		offset += master_partition->offset;
+		master = master_partition->master;
+	}
+
 	part.name = name;
 	part.size = length;
 	part.offset = offset;
-- 
2.2.0.rc0.207.ga3a616c




More information about the linux-mtd mailing list