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