lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <36f1f675-fe7c-fc6a-78ae-adc42a23e403@gmail.com>
Date:   Sun, 4 Jun 2017 13:06:29 +0200
From:   Heiner Kallweit <hkallweit1@...il.com>
To:     Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH] nvmem: core: add managed version of nvmem_register

Add a device-managed version of nvmem_register.

Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
 Documentation/nvmem/nvmem.txt  |  1 +
 drivers/nvmem/core.c           | 35 +++++++++++++++++++++++++++++++++++
 include/linux/nvmem-provider.h |  7 +++++++
 3 files changed, 43 insertions(+)

diff --git a/Documentation/nvmem/nvmem.txt b/Documentation/nvmem/nvmem.txt
index dbd40d87..b4ff7862 100644
--- a/Documentation/nvmem/nvmem.txt
+++ b/Documentation/nvmem/nvmem.txt
@@ -37,6 +37,7 @@ and write the non-volatile memory.
 A NVMEM provider can register with NVMEM core by supplying relevant
 nvmem configuration to nvmem_register(), on success core would return a valid
 nvmem_device pointer.
+devm_nvmem_register() is a device-managed version of nvmem_register.
 
 nvmem_unregister(nvmem) is used to unregister a previously registered provider.
 
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 783eb431..55db219f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -531,6 +531,41 @@ int nvmem_unregister(struct nvmem_device *nvmem)
 }
 EXPORT_SYMBOL_GPL(nvmem_unregister);
 
+static void devm_nvmem_release(struct device *dev, void *res)
+{
+	nvmem_unregister(*(struct nvmem_device **)res);
+}
+
+/**
+ * devm_nvmem_register() - managed version of nvmem_register
+ *
+ * @config: nvmem device configuration with which nvmem device is created.
+ *
+ * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
+ * on success.
+ */
+
+struct nvmem_device *devm_nvmem_register(const struct nvmem_config *config)
+{
+	struct nvmem_device *nv, **dr;
+
+	dr = devres_alloc(devm_nvmem_release, sizeof(*dr), GFP_KERNEL);
+	if (!dr)
+		return ERR_PTR(-ENOMEM);
+
+	nv = nvmem_register(config);
+	if (IS_ERR(nv)) {
+		devres_free(dr);
+		return nv;
+	}
+
+	*dr = nv;
+	devres_add(config->dev, dr);
+
+	return nv;
+}
+EXPORT_SYMBOL_GPL(devm_nvmem_register);
+
 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 cd93416d..4b92066d 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -42,6 +42,7 @@ struct nvmem_config {
 #if IS_ENABLED(CONFIG_NVMEM)
 
 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
+struct nvmem_device *devm_nvmem_register(const struct nvmem_config *cfg);
 int nvmem_unregister(struct nvmem_device *nvmem);
 
 #else
@@ -51,6 +52,12 @@ static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline struct nvmem_device *
+			devm_nvmem_register(const struct nvmem_config *c)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline int nvmem_unregister(struct nvmem_device *nvmem)
 {
 	return -ENOSYS;
-- 
2.13.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ