mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	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:39:50 -0700	[thread overview]
Message-ID: <20190409213950.GA19223@yury-thinkpad> (raw)
In-Reply-To: <b3ce41ca-6a20-a53d-7db2-451e3e700040@rasmusvillemoes.dk>

On Tue, Apr 09, 2019 at 11:31:50PM +0200, Rasmus Villemoes wrote:
> On 09/04/2019 22.42, Yury Norov 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().
> > 
> > Signed-off-by: Yury Norov <ynorov@marvell.com>
> > ---
> >  include/linux/cpumask.h | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> > index 147bdec42215..2b87f35c586c 100644
> > --- 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);
> 
> ack, but please drop the cast. "len = strchrnul(buf, '\n') - buf;"

Indeed. See below.

Thanks,
Yury

Subject: [PATCH] cpumask: fix double string traverse in cpumask_parse

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().

Signed-off-by: Yury Norov <ynorov@marvell.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 147bdec42215..2b87f35c586c 100644
--- 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 = strchrnul(buf, '\n') - buf;
 
 	return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
 }
-- 
2.17.1


  reply	other threads:[~2019-04-09 21:39 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 [this message]
2019-04-09 21:36 ` Andrew Morton

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=20190409213950.GA19223@yury-thinkpad \
    --to=yury.norov@gmail.com \
    --cc=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 \
    /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®