diff mbox

[v1] libnvdimm, namespace: Replace kmemdup() with kstrndup()

Message ID 20180611134721.5862-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andy Shevchenko June 11, 2018, 1:47 p.m. UTC
kstrndup() takes care of '\0' terminator for the strings.

Use it here instead of kmemdup() + explicit terminating the input string.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/nvdimm/namespace_devs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Andy Shevchenko Aug. 30, 2018, 11:56 a.m. UTC | #1
On Mon, Jun 11, 2018 at 04:47:21PM +0300, Andy Shevchenko wrote:
> kstrndup() takes care of '\0' terminator for the strings.
> 
> Use it here instead of kmemdup() + explicit terminating the input string.
> 

Any comments on this?

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/nvdimm/namespace_devs.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
> index 28afdd668905..19525f025539 100644
> --- a/drivers/nvdimm/namespace_devs.c
> +++ b/drivers/nvdimm/namespace_devs.c
> @@ -270,11 +270,10 @@ static ssize_t __alt_name_store(struct device *dev, const char *buf,
>  	if (dev->driver || to_ndns(dev)->claim)
>  		return -EBUSY;
>  
> -	input = kmemdup(buf, len + 1, GFP_KERNEL);
> +	input = kstrndup(buf, len, GFP_KERNEL);
>  	if (!input)
>  		return -ENOMEM;
>  
> -	input[len] = '\0';
>  	pos = strim(input);
>  	if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
>  		rc = -EINVAL;
> -- 
> 2.17.1
>
Dave Jiang Aug. 30, 2018, 10:05 p.m. UTC | #2
On 08/30/2018 04:56 AM, Andy Shevchenko wrote:
> On Mon, Jun 11, 2018 at 04:47:21PM +0300, Andy Shevchenko wrote:
>> kstrndup() takes care of '\0' terminator for the strings.
>>
>> Use it here instead of kmemdup() + explicit terminating the input string.
>>
> 
> Any comments on this?

Applied. Sorry looks like this one got missed.

> 
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> ---
>>  drivers/nvdimm/namespace_devs.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
>> index 28afdd668905..19525f025539 100644
>> --- a/drivers/nvdimm/namespace_devs.c
>> +++ b/drivers/nvdimm/namespace_devs.c
>> @@ -270,11 +270,10 @@ static ssize_t __alt_name_store(struct device *dev, const char *buf,
>>  	if (dev->driver || to_ndns(dev)->claim)
>>  		return -EBUSY;
>>  
>> -	input = kmemdup(buf, len + 1, GFP_KERNEL);
>> +	input = kstrndup(buf, len, GFP_KERNEL);
>>  	if (!input)
>>  		return -ENOMEM;
>>  
>> -	input[len] = '\0';
>>  	pos = strim(input);
>>  	if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
>>  		rc = -EINVAL;
>> -- 
>> 2.17.1
>>
>
diff mbox

Patch

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 28afdd668905..19525f025539 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -270,11 +270,10 @@  static ssize_t __alt_name_store(struct device *dev, const char *buf,
 	if (dev->driver || to_ndns(dev)->claim)
 		return -EBUSY;
 
-	input = kmemdup(buf, len + 1, GFP_KERNEL);
+	input = kstrndup(buf, len, GFP_KERNEL);
 	if (!input)
 		return -ENOMEM;
 
-	input[len] = '\0';
 	pos = strim(input);
 	if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
 		rc = -EINVAL;