linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: David Rientjes <rientjes@google.com>,
	linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy
Date: Fri, 4 May 2018 13:45:20 +0200	[thread overview]
Message-ID: <20180504114520.GP4535@dhcp22.suse.cz> (raw)
In-Reply-To: <20180503201807.24941-1-andriy.shevchenko@linux.intel.com>

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

-- 
Michal Hocko
SUSE Labs

      reply	other threads:[~2018-05-04 11:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 20:18 [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy Andy Shevchenko
2018-05-04 11:45 ` Michal Hocko [this message]

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=20180504114520.GP4535@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    /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).