Commit 07fd2f87 authored by Brian Norris's avatar Brian Norris

mtd: partitions: pass around 'mtd_partitions' wrapper struct

For some of the core partitioning code, it helps to keep info about the
parsed partition (and who parsed them) together in one place.
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent c42c2710
...@@ -532,9 +532,10 @@ int del_mtd_device(struct mtd_info *mtd) ...@@ -532,9 +532,10 @@ int del_mtd_device(struct mtd_info *mtd)
} }
static int mtd_add_device_partitions(struct mtd_info *mtd, static int mtd_add_device_partitions(struct mtd_info *mtd,
const struct mtd_partition *real_parts, struct mtd_partitions *parts)
int nbparts)
{ {
const struct mtd_partition *real_parts = parts->parts;
int nbparts = parts->nr_parts;
int ret; int ret;
if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
...@@ -588,23 +589,27 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ...@@ -588,23 +589,27 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
const struct mtd_partition *parts, const struct mtd_partition *parts,
int nr_parts) int nr_parts)
{ {
struct mtd_partitions parsed;
int ret; int ret;
const struct mtd_partition *real_parts = NULL;
ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); memset(&parsed, 0, sizeof(parsed));
if (ret <= 0 && nr_parts && parts) {
real_parts = parts; ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
ret = nr_parts; if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) {
} /* Fall back to driver-provided partitions */
/* Didn't come up with either parsed OR fallback partitions */ parsed = (struct mtd_partitions){
if (ret < 0) { .parts = parts,
.nr_parts = nr_parts,
};
} else if (ret < 0) {
/* Didn't come up with parsed OR fallback partitions */
pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n", pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
ret); ret);
/* Don't abort on errors; we can still use unpartitioned MTD */ /* Don't abort on errors; we can still use unpartitioned MTD */
ret = 0; memset(&parsed, 0, sizeof(parsed));
} }
ret = mtd_add_device_partitions(mtd, real_parts, ret); ret = mtd_add_device_partitions(mtd, &parsed);
if (ret) if (ret)
goto out; goto out;
...@@ -625,8 +630,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ...@@ -625,8 +630,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
out: out:
/* Cleanup any parsed partitions */ /* Cleanup any parsed partitions */
if (real_parts != parts) if (parsed.parser)
kfree(real_parts); kfree(parsed.parts);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(mtd_device_parse_register); EXPORT_SYMBOL_GPL(mtd_device_parse_register);
......
...@@ -10,8 +10,11 @@ int add_mtd_device(struct mtd_info *mtd); ...@@ -10,8 +10,11 @@ int add_mtd_device(struct mtd_info *mtd);
int del_mtd_device(struct mtd_info *mtd); int del_mtd_device(struct mtd_info *mtd);
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int); int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
int del_mtd_partitions(struct mtd_info *); int del_mtd_partitions(struct mtd_info *);
struct mtd_partitions;
int parse_mtd_partitions(struct mtd_info *master, const char * const *types, int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
const struct mtd_partition **pparts, struct mtd_partitions *pparts,
struct mtd_part_parser_data *data); struct mtd_part_parser_data *data);
int __init init_mtdchar(void); int __init init_mtdchar(void);
......
...@@ -743,7 +743,7 @@ static const char * const default_mtd_part_types[] = { ...@@ -743,7 +743,7 @@ static const char * const default_mtd_part_types[] = {
* parse_mtd_partitions - parse MTD partitions * parse_mtd_partitions - parse MTD partitions
* @master: the master partition (describes whole MTD device) * @master: the master partition (describes whole MTD device)
* @types: names of partition parsers to try or %NULL * @types: names of partition parsers to try or %NULL
* @pparts: array of partitions found is returned here * @pparts: info about partitions found is returned here
* @data: MTD partition parser-specific data * @data: MTD partition parser-specific data
* *
* This function tries to find partition on MTD device @master. It uses MTD * This function tries to find partition on MTD device @master. It uses MTD
...@@ -755,12 +755,11 @@ static const char * const default_mtd_part_types[] = { ...@@ -755,12 +755,11 @@ static const char * const default_mtd_part_types[] = {
* *
* This function may return: * This function may return:
* o a negative error code in case of failure * o a negative error code in case of failure
* o zero if no partitions were found * o zero otherwise, and @pparts will describe the partitions, number of
* o a positive number of found partitions, in which case on exit @pparts will * partitions, and the parser which parsed them
* point to an array containing this number of &struct mtd_info objects.
*/ */
int parse_mtd_partitions(struct mtd_info *master, const char *const *types, int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
const struct mtd_partition **pparts, struct mtd_partitions *pparts,
struct mtd_part_parser_data *data) struct mtd_part_parser_data *data)
{ {
struct mtd_part_parser *parser; struct mtd_part_parser *parser;
...@@ -778,14 +777,16 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types, ...@@ -778,14 +777,16 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
parser ? parser->name : NULL); parser ? parser->name : NULL);
if (!parser) if (!parser)
continue; continue;
ret = (*parser->parse_fn)(master, pparts, data); ret = (*parser->parse_fn)(master, &pparts->parts, data);
pr_debug("%s: parser %s: %i\n", pr_debug("%s: parser %s: %i\n",
master->name, parser->name, ret); master->name, parser->name, ret);
mtd_part_parser_put(parser); mtd_part_parser_put(parser);
if (ret > 0) { if (ret > 0) {
printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
ret, parser->name, master->name); ret, parser->name, master->name);
return ret; pparts->nr_parts = ret;
pparts->parser = parser;
return 0;
} }
/* /*
* Stash the first error we see; only report it if no parser * Stash the first error we see; only report it if no parser
......
...@@ -73,6 +73,13 @@ struct mtd_part_parser { ...@@ -73,6 +73,13 @@ struct mtd_part_parser {
struct mtd_part_parser_data *); struct mtd_part_parser_data *);
}; };
/* Container for passing around a set of parsed partitions */
struct mtd_partitions {
const struct mtd_partition *parts;
int nr_parts;
const struct mtd_part_parser *parser;
};
extern int __register_mtd_parser(struct mtd_part_parser *parser, extern int __register_mtd_parser(struct mtd_part_parser *parser,
struct module *owner); struct module *owner);
#define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE) #define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment