1 From 08263a9ae664b24fa777d20b365601534842b236 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Wed, 21 Jun 2017 08:26:42 +0200
4 Subject: [PATCH] mtd: partitions: add helper for deleting partition
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 There are two similar functions handling deletion. One handles single
10 partition and another the whole MTD flash device. They share (duplicate)
11 some code so it makes sense to add a small helper for that part.
13 Function del_mtd_partitions has been moved a bit to keep all deleting
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
19 drivers/mtd/mtdpart.c | 75 +++++++++++++++++++++++++++++----------------------
20 1 file changed, 43 insertions(+), 32 deletions(-)
22 --- a/drivers/mtd/mtdpart.c
23 +++ b/drivers/mtd/mtdpart.c
24 @@ -363,32 +363,6 @@ static inline void free_partition(struct
29 - * This function unregisters and destroy all slave MTD objects which are
30 - * attached to the given master MTD object.
33 -int del_mtd_partitions(struct mtd_info *master)
35 - struct mtd_part *slave, *next;
38 - mutex_lock(&mtd_partitions_mutex);
39 - list_for_each_entry_safe(slave, next, &mtd_partitions, list)
40 - if (slave->master == master) {
41 - ret = del_mtd_device(&slave->mtd);
46 - list_del(&slave->list);
47 - free_partition(slave);
49 - mutex_unlock(&mtd_partitions_mutex);
54 static struct mtd_part *allocate_partition(struct mtd_info *master,
55 const struct mtd_partition *part, int partno,
57 @@ -675,6 +649,48 @@ int mtd_add_partition(struct mtd_info *m
59 EXPORT_SYMBOL_GPL(mtd_add_partition);
62 + * __mtd_del_partition - delete MTD partition
64 + * @priv: internal MTD struct for partition to be deleted
66 + * This function must be called with the partitions mutex locked.
68 +static int __mtd_del_partition(struct mtd_part *priv)
72 + err = del_mtd_device(&priv->mtd);
76 + list_del(&priv->list);
77 + free_partition(priv);
83 + * This function unregisters and destroy all slave MTD objects which are
84 + * attached to the given master MTD object.
86 +int del_mtd_partitions(struct mtd_info *master)
88 + struct mtd_part *slave, *next;
91 + mutex_lock(&mtd_partitions_mutex);
92 + list_for_each_entry_safe(slave, next, &mtd_partitions, list)
93 + if (slave->master == master) {
94 + ret = __mtd_del_partition(slave);
98 + mutex_unlock(&mtd_partitions_mutex);
103 int mtd_del_partition(struct mtd_info *master, int partno)
105 struct mtd_part *slave, *next;
106 @@ -686,12 +702,7 @@ int mtd_del_partition(struct mtd_info *m
107 (slave->mtd.index == partno)) {
108 sysfs_remove_files(&slave->mtd.dev.kobj,
109 mtd_partition_attrs);
110 - ret = del_mtd_device(&slave->mtd);
114 - list_del(&slave->list);
115 - free_partition(slave);
116 + ret = __mtd_del_partition(slave);
119 mutex_unlock(&mtd_partitions_mutex);