lkml.org 
[lkml]   [2019]   [Apr]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/5] lib: make bitmap_parselist_user() a wrapper on bitmap_parselist()
On Fri, Apr 05, 2019 at 08:32:07PM +0300, Yury Norov wrote:
> Currently we parse user data byte after byte which leads to
> overcomplification of parsing algorithm. The only user of
> bitmap_parselist_user() is not performance-critical, and so we
> can duplicate user data to kernel buffer and simply call
> bitmap_parselist(). This rework lets us unify and simplify
> bitmap_parselist() and bitmap_parselist_user(), which is done
> in the following patch.
>

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Yury Norov <ynorov@marvell.com>
> ---
> lib/bitmap.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index 98872e9025da..79ed5538617b 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -632,19 +632,22 @@ EXPORT_SYMBOL(bitmap_parselist);
> * @nmaskbits: size of bitmap, in bits.
> *
> * Wrapper for bitmap_parselist(), providing it with user buffer.
> - *
> - * We cannot have this as an inline function in bitmap.h because it needs
> - * linux/uaccess.h to get the access_ok() declaration and this causes
> - * cyclic dependencies.
> */
> int bitmap_parselist_user(const char __user *ubuf,
> unsigned int ulen, unsigned long *maskp,
> int nmaskbits)
> {
> - if (!access_ok(ubuf, ulen))
> - return -EFAULT;
> - return __bitmap_parselist((const char __force *)ubuf,
> - ulen, 1, maskp, nmaskbits);
> + char *buf;
> + int ret;
> +
> + buf = memdup_user_nul(ubuf, ulen);
> + if (IS_ERR(buf))
> + return PTR_ERR(buf);
> +
> + ret = bitmap_parselist(buf, maskp, nmaskbits);
> +
> + kfree(buf);
> + return ret;
> }
> EXPORT_SYMBOL(bitmap_parselist_user);
>
> --
> 2.17.1
>

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2019-04-08 11:31    [W:0.075 / U:14.160 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site