The filter_type logic for "none" needed to be reworked to be more
general.
As documented, return IIO_VAL_EMPTY for sampling rates in "none" type
and EINVAL when there's an attempt to write a rate for "none" type.
Signed-off-by: Ben Collins <bcollins@kernel.org>
---
drivers/iio/adc/ad4080.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/adc/ad4080.c b/drivers/iio/adc/ad4080.c
index 6e61787ed3213fe4332bd92b938a7a717dada99f..c7408b9703731ee5d4229a85ffa91ea64b233cd9 100644
--- a/drivers/iio/adc/ad4080.c
+++ b/drivers/iio/adc/ad4080.c
@@ -154,8 +154,6 @@ static const int ad4080_dec_rate_avail[] = {
2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
};
-static const int ad4080_dec_rate_none[] = { 1 };
-
static const char * const ad4080_power_supplies[] = {
"vdd33", "vdd11", "vddldo", "iovdd", "vrefin",
};
@@ -268,13 +266,13 @@ static int ad4080_read_raw(struct iio_dev *indio_dev,
*val = st->clk_rate;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- if (st->filter_type == FILTER_NONE) {
- *val = 1;
- } else {
- *val = ad4080_get_dec_rate(indio_dev, chan);
- if (*val < 0)
- return *val;
- }
+ if (st->filter_type == FILTER_NONE)
+ return IIO_VAL_EMPTY;
+
+ *val = ad4080_get_dec_rate(indio_dev, chan);
+ if (*val < 0)
+ return *val;
+
return IIO_VAL_INT;
default:
return -EINVAL;
@@ -289,7 +287,7 @@ static int ad4080_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- if (st->filter_type == FILTER_NONE && val > 1)
+ if (st->filter_type == FILTER_NONE)
return -EINVAL;
return ad4080_set_dec_rate(indio_dev, chan, val);
@@ -376,17 +374,16 @@ static int ad4080_read_avail(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
switch (st->filter_type) {
case FILTER_NONE:
- *vals = ad4080_dec_rate_none;
- *length = ARRAY_SIZE(ad4080_dec_rate_none);
+ *type = IIO_VAL_EMPTY;
break;
default:
*vals = ad4080_dec_rate_avail;
*length = st->filter_type >= SINC_5 ?
(ARRAY_SIZE(ad4080_dec_rate_avail) - 2) :
ARRAY_SIZE(ad4080_dec_rate_avail);
+ *type = IIO_VAL_INT;
break;
}
- *type = IIO_VAL_INT;
return IIO_AVAIL_LIST;
default:
return -EINVAL;
--
2.39.5
On 8/25/25 7:10 PM, Ben Collins wrote:
> The filter_type logic for "none" needed to be reworked to be more
> general.
>
> As documented, return IIO_VAL_EMPTY for sampling rates in "none" type
> and EINVAL when there's an attempt to write a rate for "none" type.
This patch breaks usespace, which is something we always must avoid.
>
> Signed-off-by: Ben Collins <bcollins@kernel.org>
> ---
> drivers/iio/adc/ad4080.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/iio/adc/ad4080.c b/drivers/iio/adc/ad4080.c
> index 6e61787ed3213fe4332bd92b938a7a717dada99f..c7408b9703731ee5d4229a85ffa91ea64b233cd9 100644
> --- a/drivers/iio/adc/ad4080.c
> +++ b/drivers/iio/adc/ad4080.c
> @@ -154,8 +154,6 @@ static const int ad4080_dec_rate_avail[] = {
> 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
> };
>
> -static const int ad4080_dec_rate_none[] = { 1 };
> -
> static const char * const ad4080_power_supplies[] = {
> "vdd33", "vdd11", "vddldo", "iovdd", "vrefin",
> };
> @@ -268,13 +266,13 @@ static int ad4080_read_raw(struct iio_dev *indio_dev,
> *val = st->clk_rate;
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> - if (st->filter_type == FILTER_NONE) {
> - *val = 1;
> - } else {
> - *val = ad4080_get_dec_rate(indio_dev, chan);
> - if (*val < 0)
> - return *val;
> - }
> + if (st->filter_type == FILTER_NONE)
> + return IIO_VAL_EMPTY;
> +
> + *val = ad4080_get_dec_rate(indio_dev, chan);
> + if (*val < 0)
> + return *val;
> +
> return IIO_VAL_INT;
> default:
> return -EINVAL;
> @@ -289,7 +287,7 @@ static int ad4080_write_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> - if (st->filter_type == FILTER_NONE && val > 1)
> + if (st->filter_type == FILTER_NONE)
> return -EINVAL;
>
> return ad4080_set_dec_rate(indio_dev, chan, val);
> @@ -376,17 +374,16 @@ static int ad4080_read_avail(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> switch (st->filter_type) {
> case FILTER_NONE:
> - *vals = ad4080_dec_rate_none;
> - *length = ARRAY_SIZE(ad4080_dec_rate_none);
> + *type = IIO_VAL_EMPTY;
> break;
> default:
> *vals = ad4080_dec_rate_avail;
> *length = st->filter_type >= SINC_5 ?
> (ARRAY_SIZE(ad4080_dec_rate_avail) - 2) :
> ARRAY_SIZE(ad4080_dec_rate_avail);
> + *type = IIO_VAL_INT;
> break;
> }
> - *type = IIO_VAL_INT;
> return IIO_AVAIL_LIST;
> default:
> return -EINVAL;
>
Returning a value of 1 for the oversampling ratio when there is no
oversampling going on is perfectly reasonable and mathematically correct.
So I don't consider this change an improvement.
On Tue, Aug 26, 2025 at 11:51:56AM -0500, David Lechner wrote:
> On 8/25/25 7:10 PM, Ben Collins wrote:
> > The filter_type logic for "none" needed to be reworked to be more
> > general.
> >
> > As documented, return IIO_VAL_EMPTY for sampling rates in "none" type
> > and EINVAL when there's an attempt to write a rate for "none" type.
>
> This patch breaks usespace, which is something we always must avoid.
I was under the impression there was a need to make the use of
filter_type "none" more consistent.
I don't disagree with not breaking userspace, but it does create
ambiguity for other implementations.
> >
> > Signed-off-by: Ben Collins <bcollins@kernel.org>
> > ---
> > drivers/iio/adc/ad4080.c | 23 ++++++++++-------------
> > 1 file changed, 10 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ad4080.c b/drivers/iio/adc/ad4080.c
> > index 6e61787ed3213fe4332bd92b938a7a717dada99f..c7408b9703731ee5d4229a85ffa91ea64b233cd9 100644
> > --- a/drivers/iio/adc/ad4080.c
> > +++ b/drivers/iio/adc/ad4080.c
> > @@ -154,8 +154,6 @@ static const int ad4080_dec_rate_avail[] = {
> > 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
> > };
> >
> > -static const int ad4080_dec_rate_none[] = { 1 };
> > -
> > static const char * const ad4080_power_supplies[] = {
> > "vdd33", "vdd11", "vddldo", "iovdd", "vrefin",
> > };
> > @@ -268,13 +266,13 @@ static int ad4080_read_raw(struct iio_dev *indio_dev,
> > *val = st->clk_rate;
> > return IIO_VAL_INT;
> > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > - if (st->filter_type == FILTER_NONE) {
> > - *val = 1;
> > - } else {
> > - *val = ad4080_get_dec_rate(indio_dev, chan);
> > - if (*val < 0)
> > - return *val;
> > - }
> > + if (st->filter_type == FILTER_NONE)
> > + return IIO_VAL_EMPTY;
> > +
> > + *val = ad4080_get_dec_rate(indio_dev, chan);
> > + if (*val < 0)
> > + return *val;
> > +
> > return IIO_VAL_INT;
> > default:
> > return -EINVAL;
> > @@ -289,7 +287,7 @@ static int ad4080_write_raw(struct iio_dev *indio_dev,
> >
> > switch (mask) {
> > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > - if (st->filter_type == FILTER_NONE && val > 1)
> > + if (st->filter_type == FILTER_NONE)
> > return -EINVAL;
> >
> > return ad4080_set_dec_rate(indio_dev, chan, val);
> > @@ -376,17 +374,16 @@ static int ad4080_read_avail(struct iio_dev *indio_dev,
> > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > switch (st->filter_type) {
> > case FILTER_NONE:
> > - *vals = ad4080_dec_rate_none;
> > - *length = ARRAY_SIZE(ad4080_dec_rate_none);
> > + *type = IIO_VAL_EMPTY;
> > break;
> > default:
> > *vals = ad4080_dec_rate_avail;
> > *length = st->filter_type >= SINC_5 ?
> > (ARRAY_SIZE(ad4080_dec_rate_avail) - 2) :
> > ARRAY_SIZE(ad4080_dec_rate_avail);
> > + *type = IIO_VAL_INT;
> > break;
> > }
> > - *type = IIO_VAL_INT;
> > return IIO_AVAIL_LIST;
> > default:
> > return -EINVAL;
> >
>
> Returning a value of 1 for the oversampling ratio when there is no
> oversampling going on is perfectly reasonable and mathematically correct.
> So I don't consider this change an improvement.
--
Ben Collins
https://libjwt.io
https://github.com/benmcollins
--
3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
On Tue, 26 Aug 2025 15:11:14 -0400
Ben Collins <bcollins@kernel.org> wrote:
> On Tue, Aug 26, 2025 at 11:51:56AM -0500, David Lechner wrote:
> > On 8/25/25 7:10 PM, Ben Collins wrote:
> > > The filter_type logic for "none" needed to be reworked to be more
> > > general.
> > >
> > > As documented, return IIO_VAL_EMPTY for sampling rates in "none" type
> > > and EINVAL when there's an attempt to write a rate for "none" type.
> >
> > This patch breaks usespace, which is something we always must avoid.
>
> I was under the impression there was a need to make the use of
> filter_type "none" more consistent.
>
> I don't disagree with not breaking userspace, but it does create
> ambiguity for other implementations.
For oversampling the value of 1 has long been used for
'not oversampling'. So I'm not seeing an ambiguity there.
Jonathan
>
> > >
> > > Signed-off-by: Ben Collins <bcollins@kernel.org>
> > > ---
> > > drivers/iio/adc/ad4080.c | 23 ++++++++++-------------
> > > 1 file changed, 10 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/drivers/iio/adc/ad4080.c b/drivers/iio/adc/ad4080.c
> > > index 6e61787ed3213fe4332bd92b938a7a717dada99f..c7408b9703731ee5d4229a85ffa91ea64b233cd9 100644
> > > --- a/drivers/iio/adc/ad4080.c
> > > +++ b/drivers/iio/adc/ad4080.c
> > > @@ -154,8 +154,6 @@ static const int ad4080_dec_rate_avail[] = {
> > > 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
> > > };
> > >
> > > -static const int ad4080_dec_rate_none[] = { 1 };
> > > -
> > > static const char * const ad4080_power_supplies[] = {
> > > "vdd33", "vdd11", "vddldo", "iovdd", "vrefin",
> > > };
> > > @@ -268,13 +266,13 @@ static int ad4080_read_raw(struct iio_dev *indio_dev,
> > > *val = st->clk_rate;
> > > return IIO_VAL_INT;
> > > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > > - if (st->filter_type == FILTER_NONE) {
> > > - *val = 1;
> > > - } else {
> > > - *val = ad4080_get_dec_rate(indio_dev, chan);
> > > - if (*val < 0)
> > > - return *val;
> > > - }
> > > + if (st->filter_type == FILTER_NONE)
> > > + return IIO_VAL_EMPTY;
> > > +
> > > + *val = ad4080_get_dec_rate(indio_dev, chan);
> > > + if (*val < 0)
> > > + return *val;
> > > +
> > > return IIO_VAL_INT;
> > > default:
> > > return -EINVAL;
> > > @@ -289,7 +287,7 @@ static int ad4080_write_raw(struct iio_dev *indio_dev,
> > >
> > > switch (mask) {
> > > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > > - if (st->filter_type == FILTER_NONE && val > 1)
> > > + if (st->filter_type == FILTER_NONE)
> > > return -EINVAL;
> > >
> > > return ad4080_set_dec_rate(indio_dev, chan, val);
> > > @@ -376,17 +374,16 @@ static int ad4080_read_avail(struct iio_dev *indio_dev,
> > > case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > > switch (st->filter_type) {
> > > case FILTER_NONE:
> > > - *vals = ad4080_dec_rate_none;
> > > - *length = ARRAY_SIZE(ad4080_dec_rate_none);
> > > + *type = IIO_VAL_EMPTY;
> > > break;
> > > default:
> > > *vals = ad4080_dec_rate_avail;
> > > *length = st->filter_type >= SINC_5 ?
> > > (ARRAY_SIZE(ad4080_dec_rate_avail) - 2) :
> > > ARRAY_SIZE(ad4080_dec_rate_avail);
> > > + *type = IIO_VAL_INT;
> > > break;
> > > }
> > > - *type = IIO_VAL_INT;
> > > return IIO_AVAIL_LIST;
> > > default:
> > > return -EINVAL;
> > >
> >
> > Returning a value of 1 for the oversampling ratio when there is no
> > oversampling going on is perfectly reasonable and mathematically correct.
> > So I don't consider this change an improvement.
>
© 2016 - 2026 Red Hat, Inc.