kernel: bump 4.14 to 4.14.158
[oweals/openwrt.git] / target / linux / generic / pending-4.14 / 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_core.c
42 +++ b/drivers/mtd/maps/physmap_of_core.c
43 @@ -105,37 +105,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 **res;
50 -       int count;
51 -
52 -       count = of_property_count_strings(dp, "linux,part-probe");
53 -       if (count < 0)
54 -               return part_probe_types_def;
55 -
56 -       res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
57 -       if (!res)
58 -               return NULL;
59 -
60 -       count = of_property_read_string_array(dp, "linux,part-probe", res,
61 -                                             count);
62 -       if (count < 0)
63 -               return NULL;
64 -
65 -       return res;
66 -}
67 -
68 -static void of_free_probes(const char * const *probes)
69 -{
70 -       if (probes != part_probe_types_def)
71 -               kfree(probes);
72 -}
73 -
74  static const struct of_device_id of_flash_match[];
75  static int of_flash_probe(struct platform_device *dev)
76  {
77 -       const char * const *part_probe_types;
78         const struct of_device_id *match;
79         struct device_node *dp = dev->dev.of_node;
80         struct resource res;
81 @@ -293,14 +265,8 @@ static int of_flash_probe(struct platfor
82  
83         info->cmtd->dev.parent = &dev->dev;
84         mtd_set_of_node(info->cmtd, dp);
85 -       part_probe_types = of_get_probes(dp);
86 -       if (!part_probe_types) {
87 -               err = -ENOMEM;
88 -               goto err_out;
89 -       }
90 -       mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
91 +       mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
92                         NULL, 0);
93 -       of_free_probes(part_probe_types);
94  
95         kfree(mtd_list);
96  
97 --- a/drivers/mtd/mtdpart.c
98 +++ b/drivers/mtd/mtdpart.c
99 @@ -29,6 +29,7 @@
100  #include <linux/kmod.h>
101  #include <linux/mtd/mtd.h>
102  #include <linux/mtd/partitions.h>
103 +#include <linux/of.h>
104  #include <linux/err.h>
105  #include <linux/of.h>
106  
107 @@ -860,6 +861,32 @@ void deregister_mtd_parser(struct mtd_pa
108  EXPORT_SYMBOL_GPL(deregister_mtd_parser);
109  
110  /*
111 + * Parses the linux,part-probe device tree property.
112 + * When a non null value is returned it has to be freed with kfree() by
113 + * the caller.
114 + */
115 +static const char * const *of_get_probes(struct device_node *dp)
116 +{
117 +       const char **res;
118 +       int count;
119 +
120 +       count = of_property_count_strings(dp, "linux,part-probe");
121 +       if (count < 0)
122 +               return NULL;
123 +
124 +       res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
125 +       if (!res)
126 +               return NULL;
127 +
128 +       count = of_property_read_string_array(dp, "linux,part-probe", res,
129 +                                             count);
130 +       if (count < 0)
131 +               return NULL;
132 +
133 +       return res;
134 +}
135 +
136 +/*
137   * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
138   * are changing this array!
139   */
140 @@ -1008,6 +1035,13 @@ int parse_mtd_partitions(struct mtd_info
141         struct mtd_partitions pparts = { };
142         struct mtd_part_parser *parser;
143         int ret, err = 0;
144 +       const char *const *types_of = NULL;
145 +
146 +       if (mtd_get_of_node(master)) {
147 +               types_of = of_get_probes(mtd_get_of_node(master));
148 +               if (types_of != NULL)
149 +                       types = types_of;
150 +       }
151  
152         if (!types)
153                 types = mtd_is_partition(master) ? default_subpartition_types :
154 @@ -1049,6 +1083,7 @@ int parse_mtd_partitions(struct mtd_info
155                 if (ret < 0 && !err)
156                         err = ret;
157         }
158 +       kfree(types_of);
159         return err;
160  }
161