Re: [PATCH v15 03/12] lib: kstrtox: add kstrtoudec64() and kstrtodec64()

From: Rodrigo Alencar

Date: Wed Jun 03 2026 - 04:14:52 EST


On 26/06/03 12:00AM, Andy Shevchenko wrote:
> On Sun, May 31, 2026 at 09:30:46AM +0100, Rodrigo Alencar via B4 Relay wrote:
> >
> > Add helpers that parses decimal numbers into 64-bit number, i.e., decimal
> > point numbers with pre-defined scale are parsed into a 64-bit value (fixed
> > precision). After the decimal point, digits beyond the specified scale
> > are ignored.
>
> ...
>
> > +static int _kstrtoudec64(const char *s, unsigned int scale, u64 *res)
> > +{
> > + u64 _res = 0;
> > + unsigned int rv_int, rv_frac;
> > +
> > + rv_int = _parse_integer(s, 10, &_res);
> > + if (rv_int & KSTRTOX_OVERFLOW)
> > + return -ERANGE;
> > + s += rv_int;
> > +
> > + if (*s == '.')
> > + s++; /* skip decimal point */
> > +
> > + rv_frac = _parse_integer_limit_init(s, 10, _res, &_res, scale);
> > + if (rv_frac & KSTRTOX_OVERFLOW)
> > + return -ERANGE;
> > + s += rv_frac;
>
> > + if (!rv_int && !rv_frac && !isdigit(*s))
>
> Do we care about isdigit() here? Why?

The check here validates the presence of digits, and
this is to cover a corner case with scale = 0 and s = ".5",
which is considered a valid input and leads to rv_int = 0 and
rv_frac = 0, outputing res = 0

--
Kind regards,

Rodrigo Alencar