linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: lee.jones@linaro.org, corbet@lwn.net
Cc: andreas.werner@men.de, tony@atomide.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-omap@vger.kernel.org, patches@opensource.wolfsonmicro.com,
	Laxman Dewangan <ldewangan@nvidia.com>
Subject: [PATCH 01/20] mfd: Add devm_ apis for mfd_add_devices and mfd_release_devices
Date: Tue, 5 Apr 2016 17:18:13 +0530	[thread overview]
Message-ID: <1459856912-17859-2-git-send-email-ldewangan@nvidia.com> (raw)
In-Reply-To: <1459856912-17859-1-git-send-email-ldewangan@nvidia.com>

Add device managed APIs devm_mfd_add_devices() and
devm_mfd_remove_devices() for the APIs mfd_add_devices()
and mfd_remove_devices().

This helps in reducing code in error path and sometimes
removal of .remove callback for driver unbind.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
 drivers/mfd/mfd-core.c   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/core.h |  7 ++++++
 2 files changed, 69 insertions(+)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 409da01..145712e 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -334,6 +334,68 @@ void mfd_remove_devices(struct device *parent)
 }
 EXPORT_SYMBOL(mfd_remove_devices);
 
+static void devm_mfd_dev_release(struct device *dev, void *res)
+{
+	mfd_remove_devices(dev);
+}
+
+/**
+ * devm_mfd_add_devices - Resource managed version of mfd_add_devices()
+ *
+ * This returns the 0 on success otherwise error number in the failure.
+ * The allocated mfd devices will automatically be released when the
+ * device is unbound.
+ */
+int devm_mfd_add_devices(struct device *dev, int id,
+		    const struct mfd_cell *cells, int n_devs,
+		    struct resource *mem_base,
+		    int irq_base, struct irq_domain *domain)
+{
+	struct device **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = mfd_add_devices(dev, id, cells, n_devs, mem_base,
+			      irq_base, domain);
+	if (!ret) {
+		*ptr = dev;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(devm_mfd_add_devices);
+
+static int devm_mfd_devs_match(struct device *dev, void *res, void *data)
+{
+	struct device **r = res;
+
+	if (WARN_ON(!r || !*r))
+		return 0;
+
+	return *r == data;
+}
+
+/**
+ * devm_mfd_remove_device - Resource managed version of mfd_remove_devices()
+ * @dev: Device for which which resource was allocated.
+ *
+ * Remove all mfd devices added on the device.
+ * Normally this function will not need to be called and the resource
+ * management code will ensure that the resource is freed.
+ */
+void devm_mfd_remove_devices(struct device *dev)
+{
+	WARN_ON(devres_release(dev, devm_mfd_dev_release,
+			       devm_mfd_devs_match, dev));
+}
+EXPORT_SYMBOL(devm_mfd_remove_devices);
+
 int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
 {
 	struct mfd_cell cell_entry;
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index bc6f7e0..d658d7f 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -131,4 +131,11 @@ static inline int mfd_add_hotplug_devices(struct device *parent,
 
 extern void mfd_remove_devices(struct device *parent);
 
+extern int devm_mfd_add_devices(struct device *dev, int id,
+			   const struct mfd_cell *cells, int n_devs,
+			   struct resource *mem_base,
+			   int irq_base, struct irq_domain *irq_domain);
+
+extern void devm_mfd_remove_devices(struct device *dev);
+
 #endif
-- 
2.1.4

  reply	other threads:[~2016-04-05 11:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 11:48 [PATCH 00/20] mfd: Add devm_ apis for mfd_add_devices and mfd_release_devices Laxman Dewangan
2016-04-05 11:48 ` Laxman Dewangan [this message]
2016-04-07 10:44   ` [PATCH 01/20] " Lee Jones
2016-04-07 10:44     ` Laxman Dewangan
2016-04-07 11:42       ` Lee Jones
2016-04-07 11:42         ` Laxman Dewangan
2016-04-05 11:48 ` [PATCH 02/20] mfd: Add resource management devm_mfd_{add,remove}_devices Laxman Dewangan
2016-04-05 11:48 ` [PATCH 03/20] mfd: act8945a: Use devm_mfd_add_devices() for mfd_device registration Laxman Dewangan
2016-04-05 11:48 ` [PATCH 04/20] mfd: as3711: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 05/20] mfd: atmel-hlcdc: " Laxman Dewangan
2016-04-05 17:09   ` Boris Brezillon
2016-04-05 11:48 ` [PATCH 06/20] mfd: bcm590xx: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 07/20] mfd: hi6421-pmic: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 08/20] mfd: lp3943: " Laxman Dewangan
2016-04-05 23:59   ` Kim, Milo
2016-04-05 11:48 ` [PATCH 09/20] mfd: menf21bmc: " Laxman Dewangan
2016-04-05 13:00   ` Andreas Werner
2016-04-05 11:48 ` [PATCH 10/20] mfd: mt6397: " Laxman Dewangan
2016-04-05 12:53   ` Javier Martinez Canillas
2016-04-05 11:48 ` [PATCH 11/20] mfd: rdc321x: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 12/20] mfd: rk808: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 13/20] mfd: rn5t618: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 14/20] mfd: rt5033: " Laxman Dewangan
2016-04-05 12:54   ` Javier Martinez Canillas
2016-04-05 11:48 ` [PATCH 15/20] mfd: sky81452: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 16/20] mfd: stw481x: " Laxman Dewangan
2016-04-05 13:18   ` Linus Walleij
2016-04-05 11:48 ` [PATCH 17/20] mfd: tps6507x: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 18/20] mfd: tps65217: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 19/20] mfd: tps65910: " Laxman Dewangan
2016-04-05 11:48 ` [PATCH 20/20] mfd: wm8400: " Laxman Dewangan
2016-04-05 13:38   ` Charles Keepax

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=1459856912-17859-2-git-send-email-ldewangan@nvidia.com \
    --to=ldewangan@nvidia.com \
    --cc=andreas.werner@men.de \
    --cc=corbet@lwn.net \
    --cc=lee.jones@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=tony@atomide.com \
    /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).