[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aHYOuzdQ_jSKA898@smile.fi.intel.com>
Date: Tue, 15 Jul 2025 11:18:03 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Sean Anderson <sean.anderson@...ux.dev>
Cc: Jonathan Cameron <jic23@...nel.org>, Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>, linux-iio@...r.kernel.org,
linux-hwmon@...r.kernel.org, Andy Shevchenko <andy@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
linux-kernel@...r.kernel.org, David Lechner <dlechner@...libre.com>
Subject: Re: [PATCH 2/7] iio: inkern: Add API for reading/writing events
On Mon, Jul 14, 2025 at 09:20:18PM -0400, Sean Anderson wrote:
> Add an in-kernel API for reading/writing event properties. Like the
> raw-to-processed conversion, with processed-to-raw we only convert the
> integer part, introducing some round-off error.
>
> A common case is for other drivers to re-expose IIO events as sysfs
> properties with a different API. To help out with this, iio_event_mode
> returns the appropriate mode. It can also be used to test for existence
> if the consumer doesn't care about read/write capability.
...
> +EXPORT_SYMBOL_GPL(iio_event_mode);
Can we move this to namespace? Otherwise it will be never ending story...
Ditto for other new APIs.
...
> + if (scale64 <= INT_MAX && scale64 >= INT_MIN)
> + raw64 = processed / (int)scale64;
Do you need the casting? (I mean if the compiler is dumb enough to not see this)
...
> + case IIO_VAL_INT_PLUS_MICRO:
> + scale64 = scale_val * scale * 1000000LL + scale_val2;
> + raw64 = div64_s64_rem(processed, scale64, &r);
> + raw64 = raw64 * 1000000 +
> + div64_s64(r * 1000000, scale64);
Logically this should be 1000000L, but can we somehow use the constants?
Like
scale64 = (s64)MICRO * scale_val * scale + scale_val2;
raw64 = div64_s64_rem(processed, scale64, &r);
raw64 = raw64 * (s32)MICRO +
div64_s64(r * (s64)MICRO, scale64);
> + break;
Ditto for other cases?
...
> + *raw = clamp(raw64, (s64)INT_MIN, (s64)INT_MAX);
You already have similar approach here...
...
> + ret = iio_convert_processed_to_raw_unlocked(chan, processed, &raw,
> + scale);
> + if (ret < 0)
Why ' < 0' ?
> + return ret;
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists