[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <mhjhwxulliyoitb2be3altyfcis5ir2vgndslxopy3fhvhgpf3@r6lmjnrpmpoa>
Date: Fri, 23 Jan 2026 16:29:12 +0000
From: Rodrigo Alencar <455.rodrigo.alencar@...il.com>
To: Rodrigo Alencar <455.rodrigo.alencar@...il.com>,
rodrigo.alencar@...log.com, linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, linux-doc@...r.kernel.org
Cc: Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>, Andy Shevchenko <andy@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>, Michael Hennerich <Michael.Hennerich@...log.com>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Jonathan Corbet <corbet@....net>
Subject: Re: [PATCH v5 2/8] iio: core: add fixed point parsing with 64-bit
parts
On 26/01/23 04:14PM, Rodrigo Alencar wrote:
> On 26/01/23 03:53PM, Rodrigo Alencar via B4 Relay wrote:
> > From: Rodrigo Alencar <rodrigo.alencar@...log.com>
> >
> > Add iio_str_to_fixpoint64() function that leverages simple_strtoull()
> > to parse numbers from a string.
> > A helper function __iio_str_to_fixpoint64() replaces
> > __iio_str_to_fixpoint() implementation, extending its usage for
> > 64-bit fixed-point parsing.
> >
> > Signed-off-by: Rodrigo Alencar <rodrigo.alencar@...log.com>
>
> ...
> > +static int __iio_str_to_fixpoint64(const char *str, u64 fract_mult,
> > + s64 *integer, s64 *fract, bool scale_db)
> > +{
> > + u64 i = 0, f = 0;
> > + char *end;
> > + int digit_count, precision = ffs(fract_mult);
>
> I've just noted that I should have used ffs64() here.
The idea here is that powers of 10 are a bunch of 2 and 5 factors,
so the index of first non-zero bit (from lsb to msb) is the amount of
precision we are interested in. This is used down bellow because
simple_strtoull() does not stop at your will, so we need to adjust
the precision after the fractional part parsing.
simple_strntoull() would come to fix this with max_chars parameter,
but it is not function that is exposed.
Apparently the most correct would be:
(fract_mult)? __ffs64(fract_mult) + 1 : 0;
However, ffs() still works, because we would not have more than 20 digits
when parsing u64.
Kind regards,
Rodrigo Alencar
Powered by blists - more mailing lists