]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
include/linux/cpumask.h: fix double string traverse in cpumask_parse
authorYury Norov <ynorov@marvell.com>
Tue, 14 May 2019 22:44:46 +0000 (15:44 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 15 May 2019 02:52:50 +0000 (19:52 -0700)
cpumask_parse() finds first occurrence of either or strchr() and
strlen().  We can do it better with a single call of strchrnul().

[akpm@linux-foundation.org: remove unneeded cast]
Link: http://lkml.kernel.org/r/20190409204208.12190-1-ynorov@marvell.com
Signed-off-by: Yury Norov <ynorov@marvell.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/cpumask.h

index 147bdec42215d54f6f17686492bbdcc6162f1c8b..21755471b1c317c2abb8a8daae830d7fabb44093 100644 (file)
@@ -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);
 }