Re: [PATCH v5 02/12] iio: dac: ad5686: fix input raw value check

From: Jonathan Cameron

Date: Tue May 05 2026 - 07:19:14 EST


On Fri, 01 May 2026 10:14:55 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> Fix range check for input raw value, which is off by one, i.e., for a
> 10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which
> passes the previous check, allowing an out-of-range write. The issue
> exists since the ad5686 driver was first introduced.
>
> Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters")
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
Applied this patch to the fixes-togreg branch of iio.git and marked for
stable.

Thanks,

Jonathan

> ---
> drivers/iio/dac/ad5686.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 1fc54c38b629..076fe8b8bd85 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -154,7 +154,7 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - if (val > (1 << chan->scan_type.realbits) || val < 0)
> + if (val >= (1 << chan->scan_type.realbits) || val < 0)
> return -EINVAL;
>
> mutex_lock(&st->lock);
>