mtd: move code adding (registering) partitions to the parse_mtd_partitions()
This commit slightly simplifies the code. Every parse_mtd_partitions() caller (out of two existing ones) had to add partitions & cleanup parser on its own. This moves that responsibility into the function. That change also allows dropping struct mtd_partitions argument. There is one minor behavior change caused by this cleanup. If parse_mtd_partitions() fails to add partitions (add_mtd_partitions() return an error) then mtd_device_parse_register() will still try to add (register) fallback partitions. It's a real corner case affecting one of uncommon error paths and shouldn't cause any harm. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
This commit is contained in:

committed by
Boris Brezillon

parent
0fe3ede794
commit
5ac67ce36c
@@ -700,7 +700,6 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
|
||||
const struct mtd_partition *parts,
|
||||
int nr_parts)
|
||||
{
|
||||
struct mtd_partitions parsed = { };
|
||||
int ret;
|
||||
|
||||
mtd_set_dev_defaults(mtd);
|
||||
@@ -712,13 +711,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
|
||||
}
|
||||
|
||||
/* Prefer parsed partitions over driver-provided fallback */
|
||||
ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
|
||||
if (!ret && parsed.nr_parts) {
|
||||
parts = parsed.parts;
|
||||
nr_parts = parsed.nr_parts;
|
||||
}
|
||||
|
||||
if (nr_parts)
|
||||
ret = parse_mtd_partitions(mtd, types, parser_data);
|
||||
if (ret > 0)
|
||||
ret = 0;
|
||||
else if (nr_parts)
|
||||
ret = add_mtd_partitions(mtd, parts, nr_parts);
|
||||
else if (!device_is_registered(&mtd->dev))
|
||||
ret = add_mtd_device(mtd);
|
||||
@@ -744,8 +740,6 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
|
||||
}
|
||||
|
||||
out:
|
||||
/* Cleanup any parsed partitions */
|
||||
mtd_part_parser_cleanup(&parsed);
|
||||
if (ret && device_is_registered(&mtd->dev))
|
||||
del_mtd_device(mtd);
|
||||
|
||||
|
Reference in New Issue
Block a user