Re: [PATCH 2/5] lib: rework bitmap_parselist
From: Andy Shevchenko
Date: Mon Apr 08 2019 - 05:55:48 EST
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