[v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy
diff mbox

Message ID 20180503201807.24941-1-andriy.shevchenko@linux.intel.com
State New
Headers show

Commit Message

Andy Shevchenko May 3, 2018, 8:18 p.m. UTC
Using kstrndup() simplifies the code.

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

Comments

Michal Hocko May 4, 2018, 11:45 a.m. UTC | #1
On Thu 03-05-18 23:18:07, Andy Shevchenko wrote:
> Using kstrndup() simplifies the code.

if for nothing else then the len+1 being handled by kstrndup is an
improvement.

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/vmpressure.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 85350ce2d25d..7142207224d3 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -390,12 +390,11 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
>  	char *token;
>  	int ret = 0;
>  
> -	spec_orig = spec = kzalloc(MAX_VMPRESSURE_ARGS_LEN + 1, GFP_KERNEL);
> +	spec_orig = spec = kstrndup(args, MAX_VMPRESSURE_ARGS_LEN, GFP_KERNEL);
>  	if (!spec) {
>  		ret = -ENOMEM;
>  		goto out;
>  	}
> -	strncpy(spec, args, MAX_VMPRESSURE_ARGS_LEN);
>  
>  	/* Find required level */
>  	token = strsep(&spec, ",");
> -- 
> 2.17.0

Patch
diff mbox

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 85350ce2d25d..7142207224d3 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -390,12 +390,11 @@  int vmpressure_register_event(struct mem_cgroup *memcg,
 	char *token;
 	int ret = 0;
 
-	spec_orig = spec = kzalloc(MAX_VMPRESSURE_ARGS_LEN + 1, GFP_KERNEL);
+	spec_orig = spec = kstrndup(args, MAX_VMPRESSURE_ARGS_LEN, GFP_KERNEL);
 	if (!spec) {
 		ret = -ENOMEM;
 		goto out;
 	}
-	strncpy(spec, args, MAX_VMPRESSURE_ARGS_LEN);
 
 	/* Find required level */
 	token = strsep(&spec, ",");