Fixed x86 GRUB config label
[librecmc/librecmc.git] / target / linux / generic / patches-4.1 / 140-mtd-part-add-generic-parsing-of-linux-part-probe.patch
1 From 173b0add0cff6558f950c0cb1eacfb729d482711 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 4/8] 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                  | 40 +-----------------------
15  drivers/mtd/mtdpart.c                          | 43 ++++++++++++++++++++++++++
16  3 files changed, 60 insertions(+), 39 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,45 +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 -       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 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 @@ -310,10 +274,8 @@ static int of_flash_probe(struct platfor
92                 goto err_out;
93  
94         ppdata.of_node = dp;
95 -       part_probe_types = of_get_probes(dp);
96 -       mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
97 +       mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
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/kconfig.h>
112  
113 @@ -719,6 +720,40 @@ void deregister_mtd_parser(struct mtd_pa
114  EXPORT_SYMBOL_GPL(deregister_mtd_parser);
115  
116  /*
117 + * Parses the linux,part-probe device tree property.
118 + * When a non null value is returned it has to be freed with kfree() by
119 + * the caller.
120 + */
121 +static const char * const *of_get_probes(struct device_node *dp)
122 +{
123 +       const char *cp;
124 +       int cplen;
125 +       unsigned int l;
126 +       unsigned int count;
127 +       const char **res;
128 +
129 +       cp = of_get_property(dp, "linux,part-probe", &cplen);
130 +       if (cp == NULL)
131 +               return NULL;
132 +
133 +       count = 0;
134 +       for (l = 0; l != cplen; l++)
135 +               if (cp[l] == 0)
136 +                       count++;
137 +
138 +       res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
139 +       count = 0;
140 +       while (cplen > 0) {
141 +               res[count] = cp;
142 +               l = strlen(cp) + 1;
143 +               cp += l;
144 +               cplen -= l;
145 +               count++;
146 +       }
147 +       return res;
148 +}
149 +
150 +/*
151   * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
152   * are changing this array!
153   */
154 @@ -754,6 +789,13 @@ int parse_mtd_partitions(struct mtd_info
155  {
156         struct mtd_part_parser *parser;
157         int ret = 0;
158 +       const char *const *types_of = NULL;
159 +
160 +       if (data && data->of_node) {
161 +               types_of = of_get_probes(data->of_node);
162 +               if (types_of != NULL)
163 +                       types = types_of;
164 +       }
165  
166         if (!types)
167                 types = default_mtd_part_types;
168 @@ -772,6 +814,7 @@ int parse_mtd_partitions(struct mtd_info
169                         break;
170                 }
171         }
172 +       kfree(types_of);
173         return ret;
174  }
175