kernel: add linux 4.4 support
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-4.4 / 401-mtd-add-support-for-different-partition-parser-types.patch
1 From 02cff0ccaa6d364f5c1eeea83f47ac80ccc967d4 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Tue, 3 Sep 2013 18:11:50 +0200
4 Subject: [PATCH] mtd: add support for different partition parser types
5
6 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
7 ---
8 drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
9 include/linux/mtd/partitions.h | 11 ++++++++
10 2 files changed, 67 insertions(+)
11
12 --- a/drivers/mtd/mtdpart.c
13 +++ b/drivers/mtd/mtdpart.c
14 @@ -747,6 +747,30 @@ static struct mtd_part_parser *get_parti
15
16 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
17
18 +static struct mtd_part_parser *
19 +get_partition_parser_by_type(enum mtd_parser_type type,
20 + struct mtd_part_parser *start)
21 +{
22 + struct mtd_part_parser *p, *ret = NULL;
23 +
24 + spin_lock(&part_parser_lock);
25 +
26 + p = list_prepare_entry(start, &part_parsers, list);
27 + if (start)
28 + put_partition_parser(start);
29 +
30 + list_for_each_entry_continue(p, &part_parsers, list) {
31 + if (p->type == type && try_module_get(p->owner)) {
32 + ret = p;
33 + break;
34 + }
35 + }
36 +
37 + spin_unlock(&part_parser_lock);
38 +
39 + return ret;
40 +}
41 +
42 void register_mtd_parser(struct mtd_part_parser *p)
43 {
44 spin_lock(&part_parser_lock);
45 @@ -875,6 +899,38 @@ int parse_mtd_partitions(struct mtd_info
46 return err;
47 }
48
49 +int parse_mtd_partitions_by_type(struct mtd_info *master,
50 + enum mtd_parser_type type,
51 + struct mtd_partition **pparts,
52 + struct mtd_part_parser_data *data)
53 +{
54 + struct mtd_part_parser *prev = NULL;
55 + int ret = 0;
56 +
57 + while (1) {
58 + struct mtd_part_parser *parser;
59 +
60 + parser = get_partition_parser_by_type(type, prev);
61 + if (!parser)
62 + break;
63 +
64 + ret = (*parser->parse_fn)(master, pparts, data);
65 +
66 + if (ret > 0) {
67 + put_partition_parser(parser);
68 + printk(KERN_NOTICE
69 + "%d %s partitions found on MTD device %s\n",
70 + ret, parser->name, master->name);
71 + break;
72 + }
73 +
74 + prev = parser;
75 + }
76 +
77 + return ret;
78 +}
79 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
80 +
81 int mtd_is_partition(const struct mtd_info *mtd)
82 {
83 struct mtd_part *part;
84 --- a/include/linux/mtd/partitions.h
85 +++ b/include/linux/mtd/partitions.h
86 @@ -68,12 +68,17 @@ struct mtd_part_parser_data {
87 * Functions dealing with the various ways of partitioning the space
88 */
89
90 +enum mtd_parser_type {
91 + MTD_PARSER_TYPE_DEVICE = 0,
92 +};
93 +
94 struct mtd_part_parser {
95 struct list_head list;
96 struct module *owner;
97 const char *name;
98 int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
99 struct mtd_part_parser_data *);
100 + enum mtd_parser_type type;
101 };
102
103 extern void register_mtd_parser(struct mtd_part_parser *parser);
104 @@ -87,4 +92,9 @@ uint64_t mtd_get_device_size(const struc
105 extern void __weak arch_split_mtd_part(struct mtd_info *master,
106 const char *name, int offset, int size);
107
108 +int parse_mtd_partitions_by_type(struct mtd_info *master,
109 + enum mtd_parser_type type,
110 + struct mtd_partition **pparts,
111 + struct mtd_part_parser_data *data);
112 +
113 #endif