d93f4ba4b52f0a62454a301bb79d5a39662ab7f2
[oweals/openwrt.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
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.
12
13 Function del_mtd_partitions has been moved a bit to keep all deleting
14 stuff together.
15
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
18 ---
19  drivers/mtd/mtdpart.c | 75 +++++++++++++++++++++++++++++----------------------
20  1 file changed, 43 insertions(+), 32 deletions(-)
21
22 --- a/drivers/mtd/mtdpart.c
23 +++ b/drivers/mtd/mtdpart.c
24 @@ -363,32 +363,6 @@ static inline void free_partition(struct
25         kfree(p);
26  }
27  
28 -/*
29 - * This function unregisters and destroy all slave MTD objects which are
30 - * attached to the given master MTD object.
31 - */
32 -
33 -int del_mtd_partitions(struct mtd_info *master)
34 -{
35 -       struct mtd_part *slave, *next;
36 -       int ret, err = 0;
37 -
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);
42 -                       if (ret < 0) {
43 -                               err = ret;
44 -                               continue;
45 -                       }
46 -                       list_del(&slave->list);
47 -                       free_partition(slave);
48 -               }
49 -       mutex_unlock(&mtd_partitions_mutex);
50 -
51 -       return err;
52 -}
53 -
54  static struct mtd_part *allocate_partition(struct mtd_info *master,
55                         const struct mtd_partition *part, int partno,
56                         uint64_t cur_offset)
57 @@ -675,6 +649,48 @@ int mtd_add_partition(struct mtd_info *m
58  }
59  EXPORT_SYMBOL_GPL(mtd_add_partition);
60  
61 +/**
62 + * __mtd_del_partition - delete MTD partition
63 + *
64 + * @priv: internal MTD struct for partition to be deleted
65 + *
66 + * This function must be called with the partitions mutex locked.
67 + */
68 +static int __mtd_del_partition(struct mtd_part *priv)
69 +{
70 +       int err;
71 +
72 +       err = del_mtd_device(&priv->mtd);
73 +       if (err)
74 +               return err;
75 +
76 +       list_del(&priv->list);
77 +       free_partition(priv);
78 +
79 +       return 0;
80 +}
81 +
82 +/*
83 + * This function unregisters and destroy all slave MTD objects which are
84 + * attached to the given master MTD object.
85 + */
86 +int del_mtd_partitions(struct mtd_info *master)
87 +{
88 +       struct mtd_part *slave, *next;
89 +       int ret, err = 0;
90 +
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);
95 +                       if (ret < 0)
96 +                               err = ret;
97 +               }
98 +       mutex_unlock(&mtd_partitions_mutex);
99 +
100 +       return err;
101 +}
102 +
103  int mtd_del_partition(struct mtd_info *master, int partno)
104  {
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);
111 -                       if (ret < 0)
112 -                               break;
113 -
114 -                       list_del(&slave->list);
115 -                       free_partition(slave);
116 +                       ret = __mtd_del_partition(slave);
117                         break;
118                 }
119         mutex_unlock(&mtd_partitions_mutex);