Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752645AbaA2O5k (ORCPT ); Wed, 29 Jan 2014 09:57:40 -0500 Received: from mail-pb0-f52.google.com ([209.85.160.52]:54108 "EHLO mail-pb0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752599AbaA2O5i (ORCPT ); Wed, 29 Jan 2014 09:57:38 -0500 From: Manish Badarkhe To: linux-kernel@vger.kernel.org Cc: broonie@kernel.org, lgirdwood@gmail.com, gregkh@linuxfoundation.org, badarkhe.manish@gmail.com Subject: [PATCH V4 1/2] devres: introduce API "devm_kstrdup" Date: Wed, 29 Jan 2014 20:27:27 +0530 Message-Id: <1391007448-26245-2-git-send-email-badarkhe.manish@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1391007448-26245-1-git-send-email-badarkhe.manish@gmail.com> References: <1391007448-26245-1-git-send-email-badarkhe.manish@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces "devm_kstrdup" API so that the device's driver can allocate memory and copy string. Signed-off-by: Manish Badarkhe --- :100644 100644 545c4de... db4e264... M drivers/base/devres.c :100644 100644 952b010... ec1b6e2... M include/linux/device.h drivers/base/devres.c | 26 ++++++++++++++++++++++++++ include/linux/device.h | 1 + 2 files changed, 27 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 545c4de..db4e264 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 diff --git a/include/linux/device.h b/include/linux/device.h index 952b010..ec1b6e2 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -626,6 +626,7 @@ static inline void *devm_kcalloc(struct device *dev, return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } extern void devm_kfree(struct device *dev, void *p); +extern char *devm_kstrdup(struct device *dev, const char *s, 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/