[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2330439.iZASKD2KPV@fw-rgant>
Date: Tue, 18 Nov 2025 16:16:11 +0100
From: Romain Gantois <romain.gantois@...tlin.com>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, Hans de Goede <hansg@...nel.org>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
linux-iio@...r.kernel.org
Subject: Re: [PATCH v3 2/5] iio: add processed write API
Hello Andy,
On Thursday, 6 November 2025 17:07:18 CET Andy Shevchenko wrote:
> On Thu, Nov 06, 2025 at 03:11:47PM +0100, Romain Gantois wrote:
> > Add a function to allow IIO consumers to write a processed value to a
> > channel.
>
> ...
>
> > +int iio_divide_by_value(int *result, s64 numerator,
> > + unsigned int type, int val, int val2)
> > +{
> > + s64 tmp_num, tmp_den;
> > +
> > + switch (type) {
> > + case IIO_VAL_INT:
> > + tmp_num = numerator;
> > + tmp_den = val;
> > + break;
> > + case IIO_VAL_INT_PLUS_MICRO:
> > + case IIO_VAL_INT_PLUS_NANO:
> > + switch (type) {
> > + case IIO_VAL_INT_PLUS_MICRO:
> > + tmp_num = MICRO;
> > + tmp_den = MICRO;
> > + break;
> > +
> > + case IIO_VAL_INT_PLUS_NANO:
> > + tmp_num = NANO;
> > + tmp_den = NANO;
> > + break;
> > + }
> >
> > + tmp_num *= numerator;
> > + tmp_den = (s64)abs(val) * tmp_den + (s64)abs(val2);
>
> Here is a subtle bug. The problematic piece is abs(). See
> https://lore.kernel.org/r/20251106152051.2361551-1-andriy.shevchenko@linux.i
> ntel.com for the answer.
Oh wow, that's a nasty one indeed.
> > +EXPORT_SYMBOL_GPL(iio_write_channel_processed_scale);
>
> Can we start using namespaced exports?
>
Sounds good, but won't it look strange to have only
iio_write_channel_processed_scale() use a namespaced export?
...
> > +/**
> > + * iio_write_channel_processed_scale() - scale and write processed value
> > to a given channel + * @chan: The channel being queried.
> > + * @val: Value to write.
> > + * @scale: Processed value is divided by this scale factor
during the
> > conversion. + *
> > + * This function writes a processed value to a channel. A processed value
> > means + * that this value will have the correct unit and not some device
> > internal + * representation. If the device does not support writing a
> > processed value, the + * function will query the channel's scale and
> > offset and write an appropriately + * transformed raw value.
> >
> > + * Context: May sleep.
>
> The above kernel-doc doesn't have this!
>
> > + * Return: an error code or 0.
>
> Be consistent with the existing code, and even in your own change.
>
> ("Return" section name, "Context" section presence, etc.)
I'll match the "Return" section with what I used for iio_divide_by_value()
then, since the format used for iio_read_channel_label() is broken.
>
> Use Perl (original) kernel-doc for now, the Python has a significant
> regression (the fix is pending to go to Linus' branch).
Thanks for the heads up.
--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists