Re: [PATCH RFC v3 4/5] iio: core: use kstrtodec64() to parse fixed-point values

From: Rodrigo Alencar

Date: Tue Oct 20 2026 - 13:13:44 EST


On 20/10/26 09:27, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> Replace the open-coded __iio_str_to_fixpoint() parser with kstrtodec64(),
> so sysfs writes of fixed-point values also accept E notation.
>
> The fractional part only keeps the sign when the integer part is zero,
> as before. The dB suffix for scale attributes is now handled by a separate
> __iio_str_to_fixpoint_units() helper. It strips an optional trailing
> newline and the "dB" or " dB" suffix before parsing.
>
> When there is no fractional part (fract_mult == 0, or dec_scale == 0 for
> 64-bit values), try base-autodetecting kstrtoll() first so hexadecimal
> and octal input keeps its meaning ("010" is still 8). Fall back to
> kstrtodec64() on -EINVAL to accept E notation.
>
> As a side effect, inputs that used to be rejected for integer-only
> attributes are now accepted. An invalid octal number such as "08" is
> parsed as decimal 8, and a fractional value such as "1.5" is rounded
> to 2.

...

> int iio_str_to_fixpoint(const char *str, int fract_mult,
> int *integer, int *fract)
> {
> - return __iio_str_to_fixpoint(str, fract_mult, integer, fract, false);
> + s64 dec64;
> + int ret;
> +
> + if (fract_mult) {
> + /* scale = ffs(fract_mult) = ffs(10^n) = ffs(2^n * 5^n) = n + 1 */
> + ret = kstrtodec64(str, ffs(fract_mult), &dec64);

As sashiko pointed out, this is breaking some test cases under
drivers/iio/test/iio-test-rescale.c because of the rounding case change.
That is in fact an issue within the test itself, witch limits the parsing
on 9 fractional digits only, requiring a relative ppm of a scaled value
to be zero. I will have that test fixed in a precursor patch.

> + if (ret)
> + return ret;
> +

...

--
Kind regards,

Rodrigo Alencar