summaryrefslogtreecommitdiff
path: root/drivers/base/devres.c
diff options
context:
space:
mode:
authorManish Badarkhe <badarkhe.manish@gmail.com>2014-01-29 18:57:27 +0400
committerMark Brown <broonie@linaro.org>2014-02-11 20:34:32 +0400
commite31108cad3deabb1a63111d7aa699ca67753c01f (patch)
tree064b0ddbd24537c667b4d308286d980770f83ac5 /drivers/base/devres.c
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
downloadlinux-e31108cad3deabb1a63111d7aa699ca67753c01f.tar.xz
devres: introduce API "devm_kstrdup"
This patch introduces "devm_kstrdup" API so that the device's driver can allocate memory and copy string. Signed-off-by: Manish Badarkhe <badarkhe.manish@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/base/devres.c')
-rw-r--r--drivers/base/devres.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 545c4de412c3..db4e264eecb6 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -791,6 +791,32 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
EXPORT_SYMBOL_GPL(devm_kmalloc);
/**
+ * devm_kstrdup - Allocate resource managed space and
+ * copy an existing string into that.
+ * @dev: Device to allocate memory for
+ * @s: the string 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.
+ */
+char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
+{
+ size_t size;
+ char *buf;
+
+ if (!s)
+ return NULL;
+
+ size = strlen(s) + 1;
+ buf = devm_kmalloc(dev, size, gfp);
+ if (buf)
+ memcpy(buf, s, size);
+ return buf;
+}
+EXPORT_SYMBOL_GPL(devm_kstrdup);
+
+/**
* devm_kfree - Resource-managed kfree
* @dev: Device this memory belongs to
* @p: Memory to free