lkml.org 
[lkml]   [2019]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] cpumask: fix double string traverse in cpumask_parse
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);
> }

\
 
 \ /
  Last update: 2019-04-09 23:37    [W:0.051 / U:5.608 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site