kernel: don't export parse_mtd_partitions_by_type() in 4.9 and 4.14
[oweals/openwrt.git] / target / linux / generic / pending-4.14 / 401-mtd-add-support-for-different-partition-parser-types.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: mtd: add support for different partition parser types
3
4 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
5 ---
6  drivers/mtd/mtdpart.c          |   56 ++++++++++++++++++++++++++++++++++++++++
7  include/linux/mtd/partitions.h |   11 ++++++++
8  2 files changed, 67 insertions(+)
9
10 --- a/drivers/mtd/mtdpart.c
11 +++ b/drivers/mtd/mtdpart.c
12 @@ -56,6 +56,10 @@ struct mtd_part {
13  };
14  
15  static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
16 +static int parse_mtd_partitions_by_type(struct mtd_info *master,
17 +                                       enum mtd_parser_type type,
18 +                                       const struct mtd_partition **pparts,
19 +                                       struct mtd_part_parser_data *data);
20  
21  /*
22   * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
23 @@ -1118,6 +1122,61 @@ void mtd_part_parser_cleanup(struct mtd_
24         }
25  }
26  
27 +static struct mtd_part_parser *
28 +get_partition_parser_by_type(enum mtd_parser_type type,
29 +                            struct mtd_part_parser *start)
30 +{
31 +       struct mtd_part_parser *p, *ret = NULL;
32 +
33 +       spin_lock(&part_parser_lock);
34 +
35 +       p = list_prepare_entry(start, &part_parsers, list);
36 +       if (start)
37 +               mtd_part_parser_put(start);
38 +
39 +       list_for_each_entry_continue(p, &part_parsers, list) {
40 +               if (p->type == type && try_module_get(p->owner)) {
41 +                       ret = p;
42 +                       break;
43 +               }
44 +       }
45 +
46 +       spin_unlock(&part_parser_lock);
47 +
48 +       return ret;
49 +}
50 +
51 +static int parse_mtd_partitions_by_type(struct mtd_info *master,
52 +                                       enum mtd_parser_type type,
53 +                                       const struct mtd_partition **pparts,
54 +                                       struct mtd_part_parser_data *data)
55 +{
56 +       struct mtd_part_parser *prev = NULL;
57 +       int ret = 0;
58 +
59 +       while (1) {
60 +               struct mtd_part_parser *parser;
61 +
62 +               parser = get_partition_parser_by_type(type, prev);
63 +               if (!parser)
64 +                       break;
65 +
66 +               ret = (*parser->parse_fn)(master, pparts, data);
67 +
68 +               if (ret > 0) {
69 +                       mtd_part_parser_put(parser);
70 +                       printk(KERN_NOTICE
71 +                              "%d %s partitions found on MTD device %s\n",
72 +                              ret, parser->name, master->name);
73 +                       break;
74 +               }
75 +
76 +               prev = parser;
77 +       }
78 +
79 +       return ret;
80 +}
81 +
82  int mtd_is_partition(const struct mtd_info *mtd)
83  {
84         struct mtd_part *part;
85 --- a/include/linux/mtd/partitions.h
86 +++ b/include/linux/mtd/partitions.h
87 @@ -73,6 +73,10 @@ struct mtd_part_parser_data {
88   * Functions dealing with the various ways of partitioning the space
89   */
90  
91 +enum mtd_parser_type {
92 +       MTD_PARSER_TYPE_DEVICE = 0,
93 +};
94 +
95  struct mtd_part_parser {
96         struct list_head list;
97         struct module *owner;
98 @@ -81,6 +85,7 @@ struct mtd_part_parser {
99         int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
100                         struct mtd_part_parser_data *);
101         void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
102 +       enum mtd_parser_type type;
103  };
104  
105  /* Container for passing around a set of parsed partitions */