dnsmasq: move feature detection inside a shell func
[openwrt/openwrt.git] / target / linux / generic / backport-4.9 / 065-v4.13-0006-mtd-partitions-add-support-for-subpartitions.patch
1 From 97519dc52b44af054d7654776e78eaa211cf1842 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:45 +0200
4 Subject: [PATCH] mtd: partitions: add support for subpartitions
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Some flash device partitions can be containers with extra subpartitions
10 (volumes). All callbacks are already capable of this additional level of
11 indirection.
12
13 This patch makes sure we always display subpartitions using a tree
14 structure and takes care of deleting subpartitions when parent gets
15 removed.
16
17 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
18 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
19 ---
20 drivers/mtd/mtdpart.c | 23 ++++++++++++++++-------
21 1 file changed, 16 insertions(+), 7 deletions(-)
22
23 --- a/drivers/mtd/mtdpart.c
24 +++ b/drivers/mtd/mtdpart.c
25 @@ -413,7 +413,7 @@ static struct mtd_part *allocate_partiti
26 * parent conditional on that option. Note, this is a way to
27 * distinguish between the master and the partition in sysfs.
28 */
29 - slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
30 + slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ?
31 &parent->dev :
32 parent->dev.parent;
33 slave->mtd.dev.of_node = part->of_node;
34 @@ -664,8 +664,17 @@ EXPORT_SYMBOL_GPL(mtd_add_partition);
35 */
36 static int __mtd_del_partition(struct mtd_part *priv)
37 {
38 + struct mtd_part *child, *next;
39 int err;
40
41 + list_for_each_entry_safe(child, next, &mtd_partitions, list) {
42 + if (child->parent == &priv->mtd) {
43 + err = __mtd_del_partition(child);
44 + if (err)
45 + return err;
46 + }
47 + }
48 +
49 sysfs_remove_files(&priv->mtd.dev.kobj, mtd_partition_attrs);
50
51 err = del_mtd_device(&priv->mtd);
52 @@ -680,16 +689,16 @@ static int __mtd_del_partition(struct mt
53
54 /*
55 * This function unregisters and destroy all slave MTD objects which are
56 - * attached to the given master MTD object.
57 + * attached to the given MTD object.
58 */
59 -int del_mtd_partitions(struct mtd_info *master)
60 +int del_mtd_partitions(struct mtd_info *mtd)
61 {
62 struct mtd_part *slave, *next;
63 int ret, err = 0;
64
65 mutex_lock(&mtd_partitions_mutex);
66 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
67 - if (slave->parent == master) {
68 + if (slave->parent == mtd) {
69 ret = __mtd_del_partition(slave);
70 if (ret < 0)
71 err = ret;
72 @@ -699,14 +708,14 @@ int del_mtd_partitions(struct mtd_info *
73 return err;
74 }
75
76 -int mtd_del_partition(struct mtd_info *master, int partno)
77 +int mtd_del_partition(struct mtd_info *mtd, int partno)
78 {
79 struct mtd_part *slave, *next;
80 int ret = -EINVAL;
81
82 mutex_lock(&mtd_partitions_mutex);
83 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
84 - if ((slave->parent == master) &&
85 + if ((slave->parent == mtd) &&
86 (slave->mtd.index == partno)) {
87 ret = __mtd_del_partition(slave);
88 break;
89 @@ -939,6 +948,6 @@ uint64_t mtd_get_device_size(const struc
90 if (!mtd_is_partition(mtd))
91 return mtd->size;
92
93 - return mtd_to_part(mtd)->parent->size;
94 + return mtd_get_device_size(mtd_to_part(mtd)->parent);
95 }
96 EXPORT_SYMBOL_GPL(mtd_get_device_size);