linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Jones <rob.jones@codethink.co.uk>
To: "Heiko Stübner" <heiko@sntech.de>
Cc: linus.walleij@linaro.org, gnurou@gmail.com, lgirdwood@gmail.com,
	broonie@kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, ian.molton@codethink.co.uk,
	ben.dooks@codethink.co.uk
Subject: Re: [PATCH 2/3] drivers/base: devres.c: Add block copy func. for managed devices
Date: Wed, 18 Jun 2014 16:52:20 +0100	[thread overview]
Message-ID: <53A1B5B4.2020704@codethink.co.uk> (raw)
In-Reply-To: <1713451.AmufNoybT7@diego>


On 18/06/14 14:05, Heiko Stübner wrote:
> Am Dienstag, 10. Juni 2014, 15:41:47 schrieb Rob Jones:
>> Add function devm_kmemdup().
>> Rationalise with devm_kstrdup() to avoid code duplication.
>>
>> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
>> Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
>> ---
>>   drivers/base/devres.c  |   42 ++++++++++++++++++++++++++++++++++--------
>>   include/linux/device.h |    2 ++
>>   2 files changed, 36 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
>> index db4e264..978bbe2 100644
>> --- a/drivers/base/devres.c
>> +++ b/drivers/base/devres.c
>> @@ -791,6 +791,20 @@ void * devm_kmalloc(struct device *dev, size_t size,
>> gfp_t gfp) EXPORT_SYMBOL_GPL(devm_kmalloc);
>>
>>   /**
>> + * static function to avoid code duplication when duplicating buffers
>> + */
>> +static void *devm_kmemdup_nochecks(struct device *dev, const void *s,
>> +				    size_t size, gfp_t gfp)
>> +{
>> +	void *buf;
>> +
>> +	buf = devm_kmalloc(dev, size, gfp);
>> +	if (buf)
>> +		memcpy(buf, s, size);
>> +	return buf;
>> +}
>> +
>> +/**
>>    * devm_kstrdup - Allocate resource managed space and
>>    *                copy an existing string into that.
>>    * @dev: Device to allocate memory for
>> @@ -802,21 +816,33 @@ EXPORT_SYMBOL_GPL(devm_kmalloc);
>>    */
>>   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;
>> +	return devm_kmemdup_nochecks(dev, s, (strlen(s)+1), gfp);
>>   }
>>   EXPORT_SYMBOL_GPL(devm_kstrdup);
> hmm, this looks like an unrelated change to me and may warrant a separate
> patch for the devm_kstrdup change.

On reflection, I agree, I'll separate out the change to devm_kstrdup() 
and resubmit.

>
>
>>   /**
>> + * 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) +{
>> +	if (!s || (size == 0))
>> +		return NULL;
>> +
>> +	return devm_kmemdup_nochecks(dev, s, size, gfp);
>> +}
>> +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,
>
>

-- 
Rob Jones
Project Manager
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575

  reply	other threads:[~2014-06-18 15:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-10 14:41 [PATCH 0/3] use managed resources for gpio-regulator probe Rob Jones
2014-06-10 14:41 ` [PATCH 1/3] drivers/gpio: devres.c: allow gpio array requests for managed devices Rob Jones
2014-06-18 13:24   ` Heiko Stübner
2014-06-18 15:56     ` Rob Jones
2014-06-10 14:41 ` [PATCH 2/3] drivers/base: devres.c: Add block copy func. " Rob Jones
2014-06-18 13:05   ` Heiko Stübner
2014-06-18 15:52     ` Rob Jones [this message]
2014-06-10 14:41 ` [PATCH 3/3] drivers/regulator: gpio-regulator.c: use managed resources for probe Rob Jones
2014-06-18 13:05   ` Heiko Stübner

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=53A1B5B4.2020704@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@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).