Re: [PATCH v5 2/8] iio: core: add fixed point parsing with 64-bit parts
From: Andy Shevchenko
Date: Mon Jan 26 2026 - 11:07:51 EST
On Mon, Jan 26, 2026 at 03:30:44PM +0000, Rodrigo Alencar wrote:
> On 26/01/26 03:20PM, Rodrigo Alencar wrote:
> > On 26/01/26 04:53PM, Andy Shevchenko wrote:
> > > On Mon, Jan 26, 2026 at 02:26:20PM +0000, Rodrigo Alencar wrote:
...
> > > Why? Can you elaborate how checking amount of digits is different to
> > > check_mul_overflow()?
> >
> > consider U64_MAX = 18_446_744_073_709_551_615 as the limit:
> > - 19_000_000_000_000_000_000 contains the same amount of digits but overflows.
> > - 18_446_744_073_710_000_000 contains the same amount of digits but overflows.
> >
> > to catch those cases, we need to check for the overflow, everytime we read a
> > character and accumulate:
> >
> > u64 acc;
> >
> > while(isdigit(*str))
> > if (check_mul_overflow(acc, 10, &acc) ||
> > check_add_overflow(acc, *str - '0', &acc))
> > return -EOVERFLOW;
> >
> > *res = acc;
> >
> > acc can get weird results if not checked.
>
> Thinking about it again, that check could be done only in the last step
> (20th for u64)
Does kstrto*() also perform only last check? I think they do for each
iteration.
--
With Best Regards,
Andy Shevchenko