Re: [PATCH v15 02/12] lib: kstrtox: add local _parse_integer_limit_init() helper
From: Rodrigo Alencar
Date: Wed Jun 03 2026 - 06:33:58 EST
On 26/06/02 10:43PM, Andy Shevchenko wrote:
> On Sun, May 31, 2026 at 09:30:45AM +0100, Rodrigo Alencar via B4 Relay wrote:
>
> > Add parsing helper that accepts an initial value for the accumulated
> > result when parsing an 64-bit integer. It reuses current implementation
> > for _parse_integer_limit(), which now consumes the new function with
> > init = 0. The diff algorithm would have the documentation header and
> > prototype of _parse_integer_limit() moved around so it is adjusted
> > according to guidelines.
>
> ...
>
> > +static unsigned int _parse_integer_limit_init(const char *s, unsigned int base,
> > + unsigned long long init,
>
> Why not name it res...
"res" is short for result and this is an init value. I suppose the compiler
can optmize towards that kinda of efficiency. I thought of "p" itself to
carry the init value, and the function would just accumulate, but that would
change expectations on the function behavior.
> > + unsigned long long *p,
> > + size_t max_chars)
> > {
> > unsigned long long res;
>
> ...and drop this one...
>
> > unsigned int rv;
> >
> > - res = 0;
> > + res = init;
>
> ...and this one?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
--
Kind regards,
Rodrigo Alencar