1 From 5ac67ce36cfe38b4c104a42ce52c5c8d526f1c95 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 27 Mar 2018 22:35:41 +0200
4 Subject: [PATCH] mtd: move code adding (registering) partitions to the
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 This commit slightly simplifies the code. Every parse_mtd_partitions()
11 caller (out of two existing ones) had to add partitions & cleanup parser
12 on its own. This moves that responsibility into the function.
14 That change also allows dropping struct mtd_partitions argument.
16 There is one minor behavior change caused by this cleanup. If
17 parse_mtd_partitions() fails to add partitions (add_mtd_partitions()
18 return an error) then mtd_device_parse_register() will still try to
19 add (register) fallback partitions. It's a real corner case affecting
20 one of uncommon error paths and shouldn't cause any harm.
22 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
23 Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
25 drivers/mtd/mtdcore.c | 14 ++++----------
26 drivers/mtd/mtdcore.h | 1 -
27 drivers/mtd/mtdpart.c | 44 ++++++++++++++++----------------------------
28 3 files changed, 20 insertions(+), 39 deletions(-)
30 --- a/drivers/mtd/mtdcore.c
31 +++ b/drivers/mtd/mtdcore.c
32 @@ -686,7 +686,6 @@ int mtd_device_parse_register(struct mtd
33 const struct mtd_partition *parts,
36 - struct mtd_partitions parsed = { };
39 mtd_set_dev_defaults(mtd);
40 @@ -698,13 +697,10 @@ int mtd_device_parse_register(struct mtd
43 /* Prefer parsed partitions over driver-provided fallback */
44 - ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
45 - if (!ret && parsed.nr_parts) {
46 - parts = parsed.parts;
47 - nr_parts = parsed.nr_parts;
51 + ret = parse_mtd_partitions(mtd, types, parser_data);
55 ret = add_mtd_partitions(mtd, parts, nr_parts);
56 else if (!device_is_registered(&mtd->dev))
57 ret = add_mtd_device(mtd);
58 @@ -730,8 +726,6 @@ int mtd_device_parse_register(struct mtd
62 - /* Cleanup any parsed partitions */
63 - mtd_part_parser_cleanup(&parsed);
64 if (ret && device_is_registered(&mtd->dev))
67 --- a/drivers/mtd/mtdcore.h
68 +++ b/drivers/mtd/mtdcore.h
69 @@ -15,7 +15,6 @@ int del_mtd_partitions(struct mtd_info *
70 struct mtd_partitions;
72 int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
73 - struct mtd_partitions *pparts,
74 struct mtd_part_parser_data *data);
76 void mtd_part_parser_cleanup(struct mtd_partitions *parts);
77 --- a/drivers/mtd/mtdpart.c
78 +++ b/drivers/mtd/mtdpart.c
79 @@ -383,20 +383,7 @@ static inline void free_partition(struct
81 static int mtd_parse_part(struct mtd_part *slave, const char *const *types)
83 - struct mtd_partitions parsed;
86 - err = parse_mtd_partitions(&slave->mtd, types, &parsed, NULL);
89 - else if (!parsed.nr_parts)
92 - err = add_mtd_partitions(&slave->mtd, parsed.parts, parsed.nr_parts);
94 - mtd_part_parser_cleanup(&parsed);
97 + return parse_mtd_partitions(&slave->mtd, types, NULL);
100 static struct mtd_part *allocate_partition(struct mtd_info *parent,
101 @@ -1006,30 +993,27 @@ static int mtd_part_of_parse(struct mtd_
105 - * parse_mtd_partitions - parse MTD partitions
106 + * parse_mtd_partitions - parse and register MTD partitions
108 * @master: the master partition (describes whole MTD device)
109 * @types: names of partition parsers to try or %NULL
110 - * @pparts: info about partitions found is returned here
111 * @data: MTD partition parser-specific data
113 - * This function tries to find partition on MTD device @master. It uses MTD
114 - * partition parsers, specified in @types. However, if @types is %NULL, then
115 - * the default list of parsers is used. The default list contains only the
116 + * This function tries to find & register partitions on MTD device @master. It
117 + * uses MTD partition parsers, specified in @types. However, if @types is %NULL,
118 + * then the default list of parsers is used. The default list contains only the
119 * "cmdlinepart" and "ofpart" parsers ATM.
120 * Note: If there are more then one parser in @types, the kernel only takes the
121 * partitions parsed out by the first parser.
123 * This function may return:
124 * o a negative error code in case of failure
125 - * o zero otherwise, and @pparts will describe the partitions, number of
126 - * partitions, and the parser which parsed them. Caller must release
127 - * resources with mtd_part_parser_cleanup() when finished with the returned
129 + * o number of found partitions otherwise
131 int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
132 - struct mtd_partitions *pparts,
133 struct mtd_part_parser_data *data)
135 + struct mtd_partitions pparts = { };
136 struct mtd_part_parser *parser;
139 @@ -1043,7 +1027,7 @@ int parse_mtd_partitions(struct mtd_info
140 * handled in a separated function.
142 if (!strcmp(*types, "ofpart")) {
143 - ret = mtd_part_of_parse(master, pparts);
144 + ret = mtd_part_of_parse(master, &pparts);
146 pr_debug("%s: parsing partitions %s\n", master->name,
148 @@ -1054,13 +1038,17 @@ int parse_mtd_partitions(struct mtd_info
149 parser ? parser->name : NULL);
152 - ret = mtd_part_do_parse(parser, master, pparts, data);
153 + ret = mtd_part_do_parse(parser, master, &pparts, data);
155 mtd_part_parser_put(parser);
157 /* Found partitions! */
161 + err = add_mtd_partitions(master, pparts.parts,
163 + mtd_part_parser_cleanup(&pparts);
164 + return err ? err : pparts.nr_parts;
167 * Stash the first error we see; only report it if no parser