[PATCH v2 3/3] mtdpart: Allow deleting a partition with another partition as master

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


This patch makes MTD dynamic partitioning more flexible by allowing
partitions to be deleted by referencing any partition with the same
master. For example, if you have /dev/mtd0 and /dev/mtd1 both
partitions on the same underlying device, then you can call
BLKPG_DEL_PARTITION with an fd of /dev/mtd0 and pno of 1, and
/dev/mtd1 will be deleted (as opposed to returning EINVAL to signal a
missing partition, which it did previously).

Signed-off-by: Dan Ehrenberg <dehrenberg at chromium.org>
---
 drivers/mtd/mtdpart.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 7eb9083..7874bbd 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -600,6 +600,15 @@ int mtd_del_partition(struct mtd_info *master, int partno)
 	struct mtd_part *slave, *next;
 	int ret = -EINVAL;
 
+	/* If del_partition was called as a partition, just treat
+	 * this as if it were called on its master. This is a harmless
+	 * generalization and lets partitions be deleted in a system
+	 * where they are sometimes already present on boot */
+	if (mtd_is_partition(master)) {
+		struct mtd_part *master_partition = PART(master);
+		master = master_partition->master;
+	}
+
 	mutex_lock(&mtd_partitions_mutex);
 	list_for_each_entry_safe(slave, next, &mtd_partitions, list)
 		if ((slave->master == master) &&
-- 
2.2.0.rc0.207.ga3a616c




More information about the linux-mtd mailing list