All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Richard Weinberger <richard@nod.at>,
	Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>
Cc: linux-mtd@lists.infradead.org,
	"Jonas Gorski" <jonas.gorski@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V3 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions
Date: Mon, 15 Jan 2018 15:35:18 +0100	[thread overview]
Message-ID: <20180115143519.9845-2-zajec5@gmail.com> (raw)
In-Reply-To: <20180115143519.9845-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

This change is a small cleanup of mtd_device_parse_register. When using
MTD_PARTITIONED_MASTER it makes sure a master MTD is registered before
dealing with partitions. There are 2 advantages of this:
1) Not mixing code handling master MTD with code handling partitions
2) Possibility of reusing mtd_parse_part in the future to avoid some
   code duplication.

This commit doesn't change any behavior except from a slightly different
failure code path. The new code may need to call del_mtd_device when
something goes wrong.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Use device_is_registered (thanks Boris)
    Add an empty line before "return ret;"
V3: Use device_is_registered also in a out code path
---
 drivers/mtd/mtdcore.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index f80e911b8843..3304199cca07 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -641,20 +641,12 @@ static int mtd_add_device_partitions(struct mtd_info *mtd,
 {
 	const struct mtd_partition *real_parts = parts->parts;
 	int nbparts = parts->nr_parts;
-	int ret;
 
-	if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
-		ret = add_mtd_device(mtd);
-		if (ret)
-			return ret;
-	}
+	if (!nbparts && !device_is_registered(&mtd->dev))
+		return add_mtd_device(mtd);
 
-	if (nbparts > 0) {
-		ret = add_mtd_partitions(mtd, real_parts, nbparts);
-		if (ret && IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
-			del_mtd_device(mtd);
-		return ret;
-	}
+	if (nbparts > 0)
+		return add_mtd_partitions(mtd, real_parts, nbparts);
 
 	return 0;
 }
@@ -714,6 +706,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 
 	mtd_set_dev_defaults(mtd);
 
+	if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
+		ret = add_mtd_device(mtd);
+		if (ret)
+			return ret;
+	}
+
 	memset(&parsed, 0, sizeof(parsed));
 
 	ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
@@ -753,6 +751,9 @@ 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);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
-- 
2.11.0

  reply	other threads:[~2018-01-15 14:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 14:40 [PATCH 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-12 14:40 ` [PATCH 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-12 15:01   ` Boris Brezillon
2018-01-15 10:58     ` Rafał Miłecki
2018-01-12 14:40 ` [PATCH 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-12 15:11   ` Boris Brezillon
2018-01-15 12:56     ` Rafał Miłecki
2018-01-15 13:22 ` [PATCH V2 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 13:22   ` [PATCH V2 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-15 13:36     ` Boris Brezillon
2018-01-15 13:22   ` [PATCH V2 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-15 14:35   ` [PATCH V3 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 14:35     ` Rafał Miłecki [this message]
2018-01-15 14:35     ` [PATCH V3 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-15 22:45     ` [PATCH V4 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 22:45       ` [PATCH V4 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-15 22:45       ` [PATCH V4 2/2] mtd: get rid of the mtd_add_device_partitions() Rafał Miłecki
     [not found]       ` <20180116154542.9767-1-zajec5@gmail.com>
2018-02-17  8:38         ` [PATCH V5 0/2] mtd: simplify mtd_device_parse_register() code Boris Brezillon
2018-02-18  7:50           ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180115143519.9845-2-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=jonas.gorski@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=rafal@milecki.pl \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.