mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Amritha Nambiar <amritha.nambiar@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Tejun Heo <tj@kernel.org>, Willem de Bruijn <willemb@google.com>,
	Yury Norov <ynorov@marvell.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpumask: fix double string traverse in cpumask_parse
Date: Tue, 9 Apr 2019 14:36:41 -0700	[thread overview]
Message-ID: <20190409143641.960ac8fae3293b2d1a834cfa@linux-foundation.org> (raw)
In-Reply-To: <20190409204208.12190-1-ynorov@marvell.com>

On Tue,  9 Apr 2019 13:42:08 -0700 Yury Norov <yury.norov@gmail.com> wrote:

> From: Yury Norov <ynorov@marvell.com>
> 
> cpumask_parse() finds first occurrence of either \n or \0 by calling
> strchr() and strlen(). We can do it better with a single call of
> strchrnul().

Fair enough.

> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h
> @@ -633,8 +633,7 @@ static inline int cpumask_parselist_user(const char __user *buf, int len,
>   */
>  static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
>  {
> -	char *nl = strchr(buf, '\n');
> -	unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
> +	unsigned int len = (unsigned int)(strchrnul(buf, '\n') - buf);

Does the cast do anything useful?  The compiler will convert a
ptrdiff_t to uint without issues, I think?

>  	return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
>  }


      parent reply	other threads:[~2019-04-09 21:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 20:42 Yury Norov
2019-04-09 21:31 ` Rasmus Villemoes
2019-04-09 21:39   ` Yury Norov
2019-04-09 21:36 ` Andrew Morton [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=20190409143641.960ac8fae3293b2d1a834cfa@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=amritha.nambiar@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=tj@kernel.org \
    --cc=willemb@google.com \
    --cc=ynorov@marvell.com \
    --cc=yury.norov@gmail.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

all inboxes | Powered by JetHome®