lkml.org 
[lkml]   [2019]   [Apr]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/5] lib: rework bitmap_parselist
On Fri, Apr 05, 2019 at 08:32:08PM +0300, Yury Norov wrote:
> Remove __bitmap_parselist helper and split the function to logical
> parts.

> +static const char *bitmap_getnum(const char *str, unsigned int *num)
> +{
> + unsigned int n = 0, _num = 0;
> +
> + if (!isdigit(*str))
> + return ERR_PTR(-EINVAL);
> +
> + for (; isdigit(*str); str++) {
> + _num = _num * 10 + (*str - '0');
> + if (_num < n)
> + return ERR_PTR(-EOVERFLOW);
> +
> + n = _num;
> + }
> +
> + *num = _num;
> +
> + return str;
> +}

This looks like (semi) open coded simple_strtoull()

unsigned long long _num;
char *endp;

_num = simple_strtoull(str, &endp, 10);
if (endp == str)
return ERR_PTR(-EINVAL);
if (_num > UINT_MAX || (endp - str) > 10)
return ERR_PTR(-EOVERFLOW);
*num = _num;
return endp;

> +static inline bool end_of_str(char c)
> +{
> + return c == '\0' || c == '\n';
> +}

This reminds me a check at the end of _kstrtoull(). Can we use same approach in
both cases?

--
With Best Regards,
Andy Shevchenko


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