[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1404295551-13470-2-git-send-email-rob.jones@codethink.co.uk>
Date: Wed, 2 Jul 2014 11:05:49 +0100
From: Rob Jones <rob.jones@...ethink.co.uk>
To: linus.walleij@...aro.org, gnurou@...il.com
Cc: lgirdwood@...il.com, broonie@...nel.org,
linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kernel@...ethink.co.uk, ian.molton@...ethink.co.uk,
ben.dooks@...ethink.co.uk, heiko@...ech.de,
rob.jones@...ethink.co.uk
Subject: [PATCH V2 1/3] base: Add block copy func. for managed devices
Add function devm_kmemdup() which is exactly analogous to the
non-managed device function kmemdup().
Reviewed-by: Ian Molton <ian.molton@...ethink.co.uk>
Signed-off-by: Rob Jones <rob.jones@...ethink.co.uk>
---
drivers/base/devres.c | 25 +++++++++++++++++++++++++
include/linux/device.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index db4e264..77a6ce7 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -817,6 +817,31 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
EXPORT_SYMBOL_GPL(devm_kstrdup);
/**
+ * devm_kmemdup - Allocate resource managed space and
+ * copy existing data into that.
+ * @dev: Device to allocate memory for
+ * @s: The memory block to duplicate
+ * @gfp: The GFP mask used in the devm_kmalloc() call when
+ * allocating memory
+ * RETURNS:
+ * Pointer to allocated string on success, NULL on failure.
+ */
+void *devm_kmemdup(struct device *dev, const void *s, size_t size, gfp_t gfp)
+{
+ void *buf;
+
+ if (!s || (size == 0))
+ return NULL;
+
+ buf = devm_kmalloc(dev, size, gfp);
+ if (buf)
+ memcpy(buf, s, size);
+
+ return buf;
+}
+EXPORT_SYMBOL_GPL(devm_kmemdup);
+
+/**
* devm_kfree - Resource-managed kfree
* @dev: Device this memory belongs to
* @p: Memory to free
diff --git a/include/linux/device.h b/include/linux/device.h
index d1d1c05..7ace116 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -623,6 +623,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 *s, size_t size, 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.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists