All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch v3 1/6] devres: introduce API "devm_kmemdup
@ 2014-04-09  0:56 Srinivas Pandruvada
  2014-04-09  0:56 ` [Patch v3 2/6] IIO: core: Introduce read_raw_multi Srinivas Pandruvada
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Srinivas Pandruvada @ 2014-04-09  0:56 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, linux-kernel, Srinivas Pandruvada

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>
---
 Documentation/driver-model/devres.txt |  1 +
 drivers/base/devres.c                 | 21 +++++++++++++++++++++
 include/linux/device.h                |  2 ++
 3 files changed, 24 insertions(+)

diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 4f7897e..4999518 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -236,6 +236,7 @@ certainly invest a bit more effort into libata core layer).
 MEM
   devm_kzalloc()
   devm_kfree()
+  devm_kmemdup()
 
 IIO
   devm_iio_device_alloc()
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index db4e264..d0914cb 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);
diff --git a/include/linux/device.h b/include/linux/device.h
index 233bbbe..0b3117a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -629,6 +629,8 @@ static inline void *devm_kcalloc(struct device *dev,
 }
 extern void devm_kfree(struct device *dev, void *p);
 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
+extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
+				gfp_t gfp);
 
 void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
 void __iomem *devm_request_and_ioremap(struct device *dev,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-04-14 21:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09  0:56 [Patch v3 1/6] devres: introduce API "devm_kmemdup Srinivas Pandruvada
2014-04-09  0:56 ` [Patch v3 2/6] IIO: core: Introduce read_raw_multi Srinivas Pandruvada
2014-04-12 16:52   ` Jonathan Cameron
2014-04-14  1:51     ` Srinivas Pandruvada
2014-04-14  7:02       ` Jonathan Cameron
2014-04-14 21:02         ` Jonathan Cameron
2014-04-09  0:56 ` [Patch v3 3/6] IIO: core: Modify scan element type Srinivas Pandruvada
2014-04-12 16:54   ` Jonathan Cameron
2014-04-09  0:56 ` [Patch v3 4/6] IIO: core: Add quaternion modifier Srinivas Pandruvada
2014-04-09  0:56 ` [Patch v3 5/6] iio: hid-sensors: Added device rotation support Srinivas Pandruvada
2014-04-12 17:21   ` Jonathan Cameron
2014-04-14  1:48     ` Srinivas Pandruvada
2014-04-14  7:00       ` Jonathan Cameron
2014-04-09  0:56 ` [Patch v3 6/6] iio: Added ABI description for quaternion Srinivas Pandruvada
2014-04-12 16:57   ` Jonathan Cameron
2014-04-12 16:39 ` [Patch v3 1/6] devres: introduce API "devm_kmemdup Jonathan Cameron
2014-04-12 19:57   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.