devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Brian Norris
	<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Boris Brezillon
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Marek Vasut <marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Richard Weinberger <richard-/L3Ra7n9ekc@public.gmane.org>
Cc: "Cyrille Pitchen"
	<cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org>,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Rafał Miłecki" <rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org>
Subject: [PATCH V6 1/5] mtd: partitions: add helper for deleting partition
Date: Fri, 26 May 2017 15:14:11 +0200	[thread overview]
Message-ID: <20170526131415.27186-2-zajec5@gmail.com> (raw)
In-Reply-To: <20170526131415.27186-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Rafał Miłecki <rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org>

There are two similar functions handling deletion. One handles single
partition and another whole MTD flash device. They share (duplicate)
some code so it makes sense to add a small helper for that part.

Function del_mtd_partitions has been moved a bit to keep all deleting
stuff together.

Signed-off-by: Rafał Miłecki <rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org>
---
V6: Introduction of this patch. It's needed by "mtd: partitions: add
    support for subpartitions"
---
 drivers/mtd/mtdpart.c | 79 +++++++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 34 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 6960e66eb7a6..92a679062903 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -363,32 +363,6 @@ static inline void free_partition(struct mtd_part *p)
 	kfree(p);
 }
 
-/*
- * This function unregisters and destroy all slave MTD objects which are
- * attached to the given master MTD object.
- */
-
-int del_mtd_partitions(struct mtd_info *master)
-{
-	struct mtd_part *slave, *next;
-	int ret, err = 0;
-
-	mutex_lock(&mtd_partitions_mutex);
-	list_for_each_entry_safe(slave, next, &mtd_partitions, list)
-		if (slave->master == master) {
-			ret = del_mtd_device(&slave->mtd);
-			if (ret < 0) {
-				err = ret;
-				continue;
-			}
-			list_del(&slave->list);
-			free_partition(slave);
-		}
-	mutex_unlock(&mtd_partitions_mutex);
-
-	return err;
-}
-
 static struct mtd_part *allocate_partition(struct mtd_info *master,
 			const struct mtd_partition *part, int partno,
 			uint64_t cur_offset)
@@ -667,6 +641,50 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 }
 EXPORT_SYMBOL_GPL(mtd_add_partition);
 
+/**
+ * __mtd_del_partition - delete MTD partition
+ *
+ * @priv: internal MTD struct for partition to be deleted
+ *
+ * This function must be called with the partitions mutex locked.
+ */
+static int __mtd_del_partition(struct mtd_part *priv)
+{
+	int err;
+
+	sysfs_remove_files(&priv->mtd.dev.kobj, mtd_partition_attrs);
+
+	err = del_mtd_device(&priv->mtd);
+	if (err)
+		return err;
+
+	list_del(&priv->list);
+	free_partition(priv);
+
+	return 0;
+}
+
+/*
+ * This function unregisters and destroy all slave MTD objects which are
+ * attached to the given master MTD object.
+ */
+int del_mtd_partitions(struct mtd_info *master)
+{
+	struct mtd_part *slave, *next;
+	int ret, err = 0;
+
+	mutex_lock(&mtd_partitions_mutex);
+	list_for_each_entry_safe(slave, next, &mtd_partitions, list)
+		if (slave->master == master) {
+			ret = __mtd_del_partition(slave);
+			if (ret < 0)
+				err = ret;
+		}
+	mutex_unlock(&mtd_partitions_mutex);
+
+	return err;
+}
+
 int mtd_del_partition(struct mtd_info *master, int partno)
 {
 	struct mtd_part *slave, *next;
@@ -676,14 +694,7 @@ int mtd_del_partition(struct mtd_info *master, int partno)
 	list_for_each_entry_safe(slave, next, &mtd_partitions, list)
 		if ((slave->master == master) &&
 		    (slave->mtd.index == partno)) {
-			sysfs_remove_files(&slave->mtd.dev.kobj,
-					   mtd_partition_attrs);
-			ret = del_mtd_device(&slave->mtd);
-			if (ret < 0)
-				break;
-
-			list_del(&slave->list);
-			free_partition(slave);
+			ret = __mtd_del_partition(slave);
 			break;
 		}
 	mutex_unlock(&mtd_partitions_mutex);
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-05-26 13:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 13:14 [PATCH V6 0/5] mtd: add support for subpartitions Rafał Miłecki
     [not found] ` <20170526131415.27186-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-26 13:14   ` Rafał Miłecki [this message]
     [not found]     ` <20170526131415.27186-2-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-20 22:50       ` [PATCH V6 1/5] mtd: partitions: add helper for deleting partition Brian Norris
     [not found]         ` <20170620225007.GB14148-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2017-06-21  5:33           ` Rafał Miłecki
2017-05-26 13:14   ` [PATCH V6 2/5] mtd: partitions: rename "master" to the "parent" where appropriate Rafał Miłecki
     [not found]     ` <20170526131415.27186-3-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-21  1:22       ` Brian Norris
2017-05-26 13:14   ` [PATCH V6 3/5] mtd: partitions: add support for subpartitions Rafał Miłecki
2017-05-26 13:14   ` [PATCH V6 4/5] mtd: partitions: add support for partition parsers Rafał Miłecki
2017-05-26 13:14   ` [PATCH V6 5/5] mtd: extract TRX parser out of bcm47xxpart into a separated module Rafał Miłecki
2017-06-21  6:26   ` [PATCH V7 0/6] mtd: add support for subpartitions Rafał Miłecki
     [not found]     ` <20170621062647.6072-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-21  6:26       ` [PATCH V7 1/6] mtd: partitions: add helper for deleting partition Rafał Miłecki
2017-06-21  6:26       ` [PATCH V7 2/6] mtd: partitions: remove sysfs files when deleting all master's partitions Rafał Miłecki
     [not found]         ` <20170621062647.6072-3-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-22 21:05           ` Brian Norris
     [not found]             ` <20170622210533.GD14148-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2017-06-22 21:40               ` Rafał Miłecki
     [not found]                 ` <CACna6rw3B5=48qbRK+vQ1gsxsZtCtJfNa=kORZY6FrCko5PJFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-06-23 17:57                   ` Brian Norris
2017-06-21  6:26       ` [PATCH V7 3/6] mtd: partitions: rename "master" to the "parent" where appropriate Rafał Miłecki
2017-06-21  6:26       ` [PATCH V7 4/6] mtd: partitions: add support for subpartitions Rafał Miłecki
2017-06-21  6:26       ` [PATCH V7 5/6] mtd: partitions: add support for partition parsers Rafał Miłecki
2017-06-21  6:26       ` [PATCH V7 6/6] mtd: extract TRX parser out of bcm47xxpart into a separated module Rafał Miłecki
2017-06-22 21:06       ` [PATCH V7 0/6] mtd: add support for subpartitions Brian Norris

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=20170526131415.27186-2-zajec5@gmail.com \
    --to=zajec5-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org \
    --cc=richard-/L3Ra7n9ekc@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).