kernel: Copy patches from kernel 4.14 to 4.19
[openwrt/staging/chunkeey.git] / target / linux / generic / pending-4.19 / 161-mtd-part-add-generic-parsing-of-linux-part-probe.patch
1 From: Hauke Mehrtens <hauke@hauke-m.de>
2 Subject: mtd: part: add generic parsing of linux,part-probe
3
4 This moves the linux,part-probe device tree parsing code from
5 physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
6 providing a reference to their device tree node in struct
7 mtd_part_parser_data.
8
9 THIS METHOD HAS BEEN DEPRECATED
10
11 Linux supports "compatible" property in the "partitions" subnode now. It
12 should be used to specify partitions format (and trigger proper parser
13 usage) if needed.
14
15 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
16 ---
17 Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
18 drivers/mtd/maps/physmap_of.c | 46 +-------------------------
19 drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
20 3 files changed, 62 insertions(+), 45 deletions(-)
21
22 --- a/Documentation/devicetree/bindings/mtd/nand.txt
23 +++ b/Documentation/devicetree/bindings/mtd/nand.txt
24 @@ -44,6 +44,22 @@ Optional NAND chip properties:
25 used by the upper layers, and you want to make your NAND
26 as reliable as possible.
27
28 +- linux,part-probe: list of name as strings of the partition parser
29 + which should be used to parse the partition table.
30 + They will be tried in the specified ordering and
31 + the next one will be used if the previous one
32 + failed.
33 +
34 + Example: linux,part-probe = "cmdlinepart", "ofpart";
35 +
36 + This is also the default value, which will be used
37 + if this attribute is not specified. It could be
38 + that the flash driver in use overwrote the default
39 + value and uses some other default.
40 +
41 + Possible values are: bcm47xxpart, afs, ar7part,
42 + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
43 +
44 The ECC strength and ECC step size properties define the correction capability
45 of a controller. Together, they say a controller can correct "{strength} bit
46 errors per {size} bytes".
47 --- a/drivers/mtd/maps/physmap_of_core.c
48 +++ b/drivers/mtd/maps/physmap_of_core.c
49 @@ -114,37 +114,9 @@ static struct mtd_info *obsolete_probe(s
50 static const char * const part_probe_types_def[] = {
51 "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
52
53 -static const char * const *of_get_probes(struct device_node *dp)
54 -{
55 - const char **res;
56 - int count;
57 -
58 - count = of_property_count_strings(dp, "linux,part-probe");
59 - if (count < 0)
60 - return part_probe_types_def;
61 -
62 - res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
63 - if (!res)
64 - return NULL;
65 -
66 - count = of_property_read_string_array(dp, "linux,part-probe", res,
67 - count);
68 - if (count < 0)
69 - return NULL;
70 -
71 - return res;
72 -}
73 -
74 -static void of_free_probes(const char * const *probes)
75 -{
76 - if (probes != part_probe_types_def)
77 - kfree(probes);
78 -}
79 -
80 static const struct of_device_id of_flash_match[];
81 static int of_flash_probe(struct platform_device *dev)
82 {
83 - const char * const *part_probe_types;
84 const struct of_device_id *match;
85 struct device_node *dp = dev->dev.of_node;
86 struct resource res;
87 @@ -310,14 +282,8 @@ static int of_flash_probe(struct platfor
88
89 info->cmtd->dev.parent = &dev->dev;
90 mtd_set_of_node(info->cmtd, dp);
91 - part_probe_types = of_get_probes(dp);
92 - if (!part_probe_types) {
93 - err = -ENOMEM;
94 - goto err_out;
95 - }
96 - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
97 + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
98 NULL, 0);
99 - of_free_probes(part_probe_types);
100
101 kfree(mtd_list);
102
103 --- a/drivers/mtd/mtdpart.c
104 +++ b/drivers/mtd/mtdpart.c
105 @@ -29,6 +29,7 @@
106 #include <linux/kmod.h>
107 #include <linux/mtd/mtd.h>
108 #include <linux/mtd/partitions.h>
109 +#include <linux/of.h>
110 #include <linux/err.h>
111 #include <linux/of.h>
112
113 @@ -844,6 +845,37 @@ void deregister_mtd_parser(struct mtd_pa
114 }
115 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
116
117 +#include <linux/version.h>
118 +
119 +/*
120 + * Parses the linux,part-probe device tree property.
121 + * When a non null value is returned it has to be freed with kfree() by
122 + * the caller.
123 + */
124 +static const char * const *of_get_probes(struct device_node *dp)
125 +{
126 + const char **res;
127 + int count;
128 +
129 + count = of_property_count_strings(dp, "linux,part-probe");
130 + if (count < 0)
131 + return NULL;
132 +
133 + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
134 + if (!res)
135 + return NULL;
136 +
137 + count = of_property_read_string_array(dp, "linux,part-probe", res,
138 + count);
139 + if (count < 0)
140 + return NULL;
141 +
142 + pr_warn("Support for the generic \"linux,part-probe\" has been deprecated and will be removed soon");
143 + BUILD_BUG_ON(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0));
144 +
145 + return res;
146 +}
147 +
148 /*
149 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
150 * are changing this array!
151 @@ -993,6 +1025,13 @@ int parse_mtd_partitions(struct mtd_info
152 struct mtd_partitions pparts = { };
153 struct mtd_part_parser *parser;
154 int ret, err = 0;
155 + const char *const *types_of = NULL;
156 +
157 + if (mtd_get_of_node(master)) {
158 + types_of = of_get_probes(mtd_get_of_node(master));
159 + if (types_of != NULL)
160 + types = types_of;
161 + }
162
163 if (!types)
164 types = mtd_is_partition(master) ? default_subpartition_types :
165 @@ -1034,6 +1073,7 @@ int parse_mtd_partitions(struct mtd_info
166 if (ret < 0 && !err)
167 err = ret;
168 }
169 + kfree(types_of);
170 return err;
171 }
172