linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: andrew.smirnov@gmail.com (Andrey Smirnov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 02/21] nvmem: Introduce devm_nvmem_(un)register()
Date: Mon,  1 Jan 2018 15:22:51 -0800	[thread overview]
Message-ID: <20180101232310.30420-3-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20180101232310.30420-1-andrew.smirnov@gmail.com>

Introduce devm_nvmem_register()/devm_nvmem_unregister() to make
.remove() unnecessary in trivial drivers.

Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Carlo Caione <carlo@caione.org>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: cphealy at gmail.com
Cc: linux-kernel at vger.kernel.org
Cc: linux-mediatek at lists.infradead.org
Cc: linux-rockchip at lists.infradead.org
Cc: linux-amlogic at lists.infradead.org
Cc: linux-arm-kernel at lists.infradead.org
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/nvmem/core.c           | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/nvmem-provider.h | 17 +++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 57cbeacfbeb2..84f07ba1f36d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -551,6 +551,47 @@ int nvmem_unregister(struct nvmem_device *nvmem)
 }
 EXPORT_SYMBOL_GPL(nvmem_unregister);
 
+static void devm_nvmem_release(struct device *dev, void *res)
+{
+	WARN_ON(nvmem_unregister(*(struct nvmem_device **)res));
+}
+
+struct nvmem_device *devm_nvmem_register(struct device *dev,
+					 const struct nvmem_config *config)
+{
+	struct nvmem_device **ptr, *nvmem;
+
+	ptr = devres_alloc(devm_nvmem_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	nvmem = nvmem_register(config);
+
+	if (!IS_ERR(nvmem)) {
+		*ptr = nvmem;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return nvmem;
+}
+EXPORT_SYMBOL_GPL(devm_nvmem_register);
+
+static int devm_nvmem_match(struct device *dev, void *res, void *data)
+{
+	struct nvmem_device **r = res;
+
+	return *r == data;
+}
+
+int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
+{
+	return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem);
+}
+EXPORT_SYMBOL(devm_nvmem_unregister);
+
+
 static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 					       struct nvmem_cell **cellp,
 					       const char *cell_id)
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 497706f5adca..493f2f529f00 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -47,6 +47,11 @@ struct nvmem_config {
 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
 int nvmem_unregister(struct nvmem_device *nvmem);
 
+struct nvmem_device *devm_nvmem_register(struct device *dev,
+					 const struct nvmem_config *cfg);
+
+int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
+
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -59,5 +64,17 @@ static inline int nvmem_unregister(struct nvmem_device *nvmem)
 	return -ENOSYS;
 }
 
+static inline struct nvmem_device *
+devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
+{
+	return nvmem_register(c);
+}
+
+static inline int
+devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
+{
+	return nvmem_unregister(nvmem);
+}
+
 #endif /* CONFIG_NVMEM */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.14.3

  parent reply	other threads:[~2018-01-01 23:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-01 23:22 [PATCH v2 00/21] Verbatim device names and devm_nvmem_(un)register() Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 01/21] nvmem: core: Allow specifying device name verbatim Andrey Smirnov
2018-01-02 11:44   ` Srinivas Kandagatla
2018-01-02 18:40     ` Andrey Smirnov
2018-01-01 23:22 ` Andrey Smirnov [this message]
2018-01-02 11:44   ` [PATCH v2 02/21] nvmem: Introduce devm_nvmem_(un)register() Srinivas Kandagatla
2018-01-02 18:40     ` Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 03/21] nvmem: vf610-ocotp: Convert to use devm_nvmem_register() Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 04/21] nvmem: imx-ocotp: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 05/21] nvmem: uniphier-efuse: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 06/21] nvmem: snvs_lgpr: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 07/21] nvmem: rockchip-efuse: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 08/21] nvmem: qfprom: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 09/21] nvmem: mtk-efuse: " Andrey Smirnov
2018-01-01 23:22 ` [PATCH v2 10/21] nvmem: meson-mx-efuse: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 11/21] nvmem: meson-efuse: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 12/21] nvmem: lpc18xx_otp: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 13/21] nvmem: imx-iim: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 14/21] nvmem: bcm-ocotp: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 15/21] nvmem: meson-efuse: Do no gate COMPILE_TEST with MESON_SM Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 16/21] nvmem: snvs_lpgpr: Convert commas to semicolons Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 17/21] nvmem: rockchip-efuse: Make use of of_device_get_match_data() Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 18/21] nvmem: vf610-ocotp: Do not use "&pdev->dev" explicitly Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 19/21] nvmem: rockchip-efuse: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 20/21] nvmem: imx-iim: " Andrey Smirnov
2018-01-01 23:23 ` [PATCH v2 21/21] nvmem: bcm-ocotp: " Andrey Smirnov

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=20180101232310.30420-3-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.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).