summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>2014-04-29 00:51:00 +0100
committerJonathan Cameron <jic23@kernel.org>2014-04-29 21:58:15 +0100
commit3046365bb470f0ec2f7cf5cb07a8ee7e4b490103 (patch)
tree66fbbb9b115c71814ff5a6e36566a47c492f0a6a /drivers/base
parent37aa48368f2508defb1976be62e1ed6ca4dde683 (diff)
devres: introduce API "devm_kmemdup
Introduce devm_kmemdup, which uses resource managed kmalloc. There are several request from maintainers to add this instead of using kmemdup. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/devres.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index db4e264eecb6..d0914cba2413 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -831,3 +831,24 @@ void devm_kfree(struct device *dev, void *p)
WARN_ON(rc);
}
EXPORT_SYMBOL_GPL(devm_kfree);
+
+/**
+ * devm_kmemdup - Resource-managed kmemdup
+ * @dev: Device this memory belongs to
+ * @src: Memory region to duplicate
+ * @len: Memory region length
+ * @gfp: GFP mask to use
+ *
+ * Duplicate region of a memory using resource managed kmalloc
+ */
+void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
+{
+ void *p;
+
+ p = devm_kmalloc(dev, len, gfp);
+ if (p)
+ memcpy(p, src, len);
+
+ return p;
+}
+EXPORT_SYMBOL_GPL(devm_kmemdup);