kernel: update kernel 4.4 to version 4.4.6
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 140-mtd-part-add-generic-parsing-of-linux-part-probe.patch
1 From 3e7056c3a369e9ef9ca804bc626b60ef6b62ee27 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 17 May 2015 18:48:38 +0200
4 Subject: [PATCH 2/3] mtd: part: add generic parsing of linux,part-probe
5
6 This moves the linux,part-probe device tree parsing code from
7 physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
8 providing a reference to their device tree node in struct
9 mtd_part_parser_data.
10
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12 ---
13 Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
14 drivers/mtd/maps/physmap_of.c | 46 +-------------------------
15 drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
16 3 files changed, 62 insertions(+), 45 deletions(-)
17
18 --- a/Documentation/devicetree/bindings/mtd/nand.txt
19 +++ b/Documentation/devicetree/bindings/mtd/nand.txt
20 @@ -12,6 +12,22 @@
21 - nand-ecc-step-size: integer representing the number of data bytes
22 that are covered by a single ECC step.
23
24 +- linux,part-probe: list of name as strings of the partition parser
25 + which should be used to parse the partition table.
26 + They will be tried in the specified ordering and
27 + the next one will be used if the previous one
28 + failed.
29 +
30 + Example: linux,part-probe = "cmdlinepart", "ofpart";
31 +
32 + This is also the default value, which will be used
33 + if this attribute is not specified. It could be
34 + that the flash driver in use overwrote the default
35 + value and uses some other default.
36 +
37 + Possible values are: bcm47xxpart, afs, ar7part,
38 + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
39 +
40 The ECC strength and ECC step size properties define the correction capability
41 of a controller. Together, they say a controller can correct "{strength} bit
42 errors per {size} bytes".
43 --- a/drivers/mtd/maps/physmap_of.c
44 +++ b/drivers/mtd/maps/physmap_of.c
45 @@ -112,47 +112,9 @@ static struct mtd_info *obsolete_probe(s
46 static const char * const part_probe_types_def[] = {
47 "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
48
49 -static const char * const *of_get_probes(struct device_node *dp)
50 -{
51 - const char *cp;
52 - int cplen;
53 - unsigned int l;
54 - unsigned int count;
55 - const char **res;
56 -
57 - cp = of_get_property(dp, "linux,part-probe", &cplen);
58 - if (cp == NULL)
59 - return part_probe_types_def;
60 -
61 - count = 0;
62 - for (l = 0; l != cplen; l++)
63 - if (cp[l] == 0)
64 - count++;
65 -
66 - res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
67 - if (!res)
68 - return NULL;
69 - count = 0;
70 - while (cplen > 0) {
71 - res[count] = cp;
72 - l = strlen(cp) + 1;
73 - cp += l;
74 - cplen -= l;
75 - count++;
76 - }
77 - return res;
78 -}
79 -
80 -static void of_free_probes(const char * const *probes)
81 -{
82 - if (probes != part_probe_types_def)
83 - kfree(probes);
84 -}
85 -
86 static const struct of_device_id of_flash_match[];
87 static int of_flash_probe(struct platform_device *dev)
88 {
89 - const char * const *part_probe_types;
90 const struct of_device_id *match;
91 struct device_node *dp = dev->dev.of_node;
92 struct resource res;
93 @@ -311,14 +273,8 @@ static int of_flash_probe(struct platfor
94 goto err_out;
95
96 ppdata.of_node = dp;
97 - part_probe_types = of_get_probes(dp);
98 - if (!part_probe_types) {
99 - err = -ENOMEM;
100 - goto err_out;
101 - }
102 - mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
103 + mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
104 NULL, 0);
105 - of_free_probes(part_probe_types);
106
107 kfree(mtd_list);
108
109 --- a/drivers/mtd/mtdpart.c
110 +++ b/drivers/mtd/mtdpart.c
111 @@ -29,6 +29,7 @@
112 #include <linux/kmod.h>
113 #include <linux/mtd/mtd.h>
114 #include <linux/mtd/partitions.h>
115 +#include <linux/of.h>
116 #include <linux/err.h>
117 #include <linux/kconfig.h>
118
119 @@ -721,6 +722,42 @@ void deregister_mtd_parser(struct mtd_pa
120 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
121
122 /*
123 + * Parses the linux,part-probe device tree property.
124 + * When a non null value is returned it has to be freed with kfree() by
125 + * the caller.
126 + */
127 +static const char * const *of_get_probes(struct device_node *dp)
128 +{
129 + const char *cp;
130 + int cplen;
131 + unsigned int l;
132 + unsigned int count;
133 + const char **res;
134 +
135 + cp = of_get_property(dp, "linux,part-probe", &cplen);
136 + if (cp == NULL)
137 + return NULL;
138 +
139 + count = 0;
140 + for (l = 0; l != cplen; l++)
141 + if (cp[l] == 0)
142 + count++;
143 +
144 + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
145 + if (!res)
146 + return NULL;
147 + count = 0;
148 + while (cplen > 0) {
149 + res[count] = cp;
150 + l = strlen(cp) + 1;
151 + cp += l;
152 + cplen -= l;
153 + count++;
154 + }
155 + return res;
156 +}
157 +
158 +/*
159 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
160 * are changing this array!
161 */
162 @@ -756,6 +793,13 @@ int parse_mtd_partitions(struct mtd_info
163 {
164 struct mtd_part_parser *parser;
165 int ret, err = 0;
166 + const char *const *types_of = NULL;
167 +
168 + if (data && data->of_node) {
169 + types_of = of_get_probes(data->of_node);
170 + if (types_of != NULL)
171 + types = types_of;
172 + }
173
174 if (!types)
175 types = default_mtd_part_types;
176 @@ -785,6 +829,7 @@ int parse_mtd_partitions(struct mtd_info
177 if (ret < 0 && !err)
178 err = ret;
179 }
180 + kfree(types_of);
181 return err;
182 }
183