linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Jones <rob.jones@codethink.co.uk>
To: linus.walleij@linaro.org, gnurou@gmail.com
Cc: lgirdwood@gmail.com, broonie@kernel.org,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel@codethink.co.uk, ian.molton@codethink.co.uk,
	ben.dooks@codethink.co.uk, heiko@sntech.de,
	rob.jones@codethink.co.uk
Subject: [PATCH 2/4] drivers/base: devres.c: Add block copy func. for managed devices
Date: Thu, 19 Jun 2014 16:46:03 +0100	[thread overview]
Message-ID: <1403192765-3258-3-git-send-email-rob.jones@codethink.co.uk> (raw)
In-Reply-To: <1403192765-3258-1-git-send-email-rob.jones@codethink.co.uk>

Add function devm_kmemdup().

Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
---
 drivers/base/devres.c  |   27 ++++++++++++++++++++++++++-
 include/linux/device.h |    2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index db4e264..9d0f64c 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -793,7 +793,7 @@ EXPORT_SYMBOL_GPL(devm_kmalloc);
 /**
  * devm_kstrdup - Allocate resource managed space and
  *                copy an existing string into that.
- * @dev: Device to allocate memory for
+ * @dev:Device to allocate memory for
  * @s: the string to duplicate
  * @gfp: the GFP mask used in the devm_kmalloc() call when
  *       allocating memory
@@ -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


  parent reply	other threads:[~2014-06-19 15:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-19 15:46 Change gpio-reulator-probe() to use managed resources Rob Jones
2014-06-19 15:46 ` [PATCH 1/4] drivers/gpio: devres.c: allow gpio array requests for managed devices Rob Jones
2014-06-20 22:29   ` [Linux-kernel] " Ben Hutchings
2014-06-19 15:46 ` Rob Jones [this message]
2014-06-20 22:31   ` [PATCH 2/4] drivers/base: devres.c: Add block copy func. " Ben Hutchings
2014-06-19 15:46 ` [PATCH 3/4] drivers/base: devres.c: use devm_kmemdup() from with devm_kstrdup() Rob Jones
2014-06-19 15:59   ` Joe Perches
2014-06-20  9:20     ` Rob Jones
2014-06-19 15:46 ` [PATCH 4/4] drivers/regulator: gpio-regulator.c: use managed resources for probe Rob Jones
2014-06-19 17:57 ` Change gpio-reulator-probe() to use managed resources Mark Brown
2014-06-20  8:38   ` Rob Jones
2014-06-20 10:20     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403192765-3258-3-git-send-email-rob.jones@codethink.co.uk \
    --to=rob.jones@codethink.co.uk \
    --cc=ben.dooks@codethink.co.uk \
    --cc=broonie@kernel.org \
    --cc=gnurou@gmail.com \
    --cc=heiko@sntech.de \
    --cc=ian.molton@codethink.co.uk \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).