1 From 2c77c57d22adb05b21cdb333a0c42bdfa0e19835 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 16 Jan 2018 16:45:41 +0100
4 Subject: [PATCH] mtd: move code adding master MTD out of
5 mtd_add_device_partitions()
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 This change is a small cleanup of mtd_device_parse_register(). When
11 using MTD_PARTITIONED_MASTER it makes sure a master MTD is registered
12 before dealing with partitions. The advantage of this is not mixing
13 code handling master MTD with code handling partitions.
15 This commit doesn't change any behavior except from a slightly different
16 failure code path. The new code may need to call del_mtd_device when
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
20 Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
22 drivers/mtd/mtdcore.c | 25 +++++++++++++------------
23 1 file changed, 13 insertions(+), 12 deletions(-)
25 --- a/drivers/mtd/mtdcore.c
26 +++ b/drivers/mtd/mtdcore.c
27 @@ -631,20 +631,12 @@ static int mtd_add_device_partitions(str
29 const struct mtd_partition *real_parts = parts->parts;
30 int nbparts = parts->nr_parts;
33 - if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
34 - ret = add_mtd_device(mtd);
38 + if (!nbparts && !device_is_registered(&mtd->dev))
39 + return add_mtd_device(mtd);
42 - ret = add_mtd_partitions(mtd, real_parts, nbparts);
43 - if (ret && IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
44 - del_mtd_device(mtd);
48 + return add_mtd_partitions(mtd, real_parts, nbparts);
52 @@ -704,6 +696,12 @@ int mtd_device_parse_register(struct mtd
54 mtd_set_dev_defaults(mtd);
56 + if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
57 + ret = add_mtd_device(mtd);
62 memset(&parsed, 0, sizeof(parsed));
64 ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
65 @@ -743,6 +741,9 @@ int mtd_device_parse_register(struct mtd
67 /* Cleanup any parsed partitions */
68 mtd_part_parser_cleanup(&parsed);
69 + if (ret && device_is_registered(&mtd->dev))
70 + del_mtd_device(mtd);
74 EXPORT_SYMBOL_GPL(mtd_device_parse_register);