Re: [PATCH] iio: adc: ti-ads8688: use read_avail for available attributes
From: Andy Shevchenko
Date: Tue Mar 24 2026 - 07:59:52 EST
On Mon, Mar 23, 2026 at 09:56:33PM +0000, Gabriel Rondon wrote:
> Convert the in_voltage_scale_available and in_voltage_offset_available
> attributes from legacy IIO_DEVICE_ATTR with custom show functions to the
> IIO framework's read_avail callback. This uses the framework's built-in
> support for _available attributes, removing the need for manual sysfs
> formatting.
>
> Precompute the available scale values at probe time since they depend on
> the reference voltage which does not change after initialization.
...
> +static const int ads8688_offset_avail[] = {
> + -(1 << (ADS8688_REALBITS - 1)),
This is fragile code (however it probably won't be exposed IRL)
if ADS8688_REALBITS == 32 this is UB in accordance with C standard.
Also the trick with -BIT(x) is harder to read than simple GENMASK().
If ADS8688_REALBITS == 1, this becomes -1 (all ones), is it correct?
> + 0,
Do not add trailing comma to a terminator.
> };
...
> static const struct attribute_group ads8688_attribute_group = {
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \
> | BIT(IIO_CHAN_INFO_SCALE) \
> | BIT(IIO_CHAN_INFO_OFFSET), \
> + .info_mask_shared_by_type_available = \
> + BIT(IIO_CHAN_INFO_SCALE) \
> + | BIT(IIO_CHAN_INFO_OFFSET), \
This is actually slightly different style to what is put in the above.
Ideally should be unified, but probably matter for another change
(if even needed).
> .scan_index = index, \
> .scan_type = { \
> .sign = 'u', \
> }
...
> - int ret;
> + int ret, i;
Why is 'i' signed?
...
> + for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) {
for (unsigned int i = 0; i < ARRAY_SIZE(st->scale_avail); i++) {
should be good.
> + st->scale_avail[i][0] = 0;
> + st->scale_avail[i][1] = ads8688_range_def[i].scale *
> + st->vref_mv;
I would leave this on a single line (it's only 81 characters).
> + }
--
With Best Regards,
Andy Shevchenko