On Fri, Mar 27, 2026 at 01:07:59PM +0200, Radu Sabau via B4 Relay wrote: > +static const char * const ad4691_gp_names[] = { "gp0", "gp1", "gp2", "gp3" }; > + > +/* > + * Valid ACC_DEPTH values where the effective divisor equals the count. > + * From Table 13: ACC_DEPTH = 2^N yields right-shift = N, divisor = 2^N. > + */ > +static const int ad4691_oversampling_ratios[] = { 1, 2, 4, 8, 16, 32 }; > [...] > +static int ad4691_set_oversampling_ratio(struct iio_dev *indio_dev, > + const struct iio_chan_spec *chan, > + int osr) > +{ > + struct ad4691_state *st = iio_priv(indio_dev); > + unsigned int i; > + > + for (i = 0; i < ARRAY_SIZE(ad4691_oversampling_ratios); i++) { > + if (ad4691_oversampling_ratios[i] != osr) > + continue; Given that ad4691_oversampling_ratios[i] is 1 << i; you can get rid of the loop using something like: if (osr < 1 || osr > 32 || !is_power_of_2(osr)) return -EINVAL; i = ilog2(osr); > + > + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); > + if (IIO_DEV_ACQUIRE_FAILED(claim)) > + return -EBUSY; > + > + st->osr[chan->scan_index] = osr; > + return regmap_write(st->regmap, > + AD4691_ACC_DEPTH_IN(chan->scan_index), osr); > + } > + > + return -EINVAL; > +} Best regards Uwe