Re: [PATCH v8 1/8] iio: dac: ad5696: properly check i2c_transfer() return value
From: Jonathan Cameron
Date: Sat Jul 18 2026 - 19:44:40 EST
On Thu, 16 Jul 2026 13:14:17 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:
> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> Verify that the expected number of i2c messages were transferred when
> ad5686_i2c_read() is called. This issue exists since the support for I2C
> devices was first introduced.
>
> Fixes: 4177381b4401 ("iio:dac:ad5686: Add AD5671R/75R/94/94R/95R/96/96R support")
> Reported-by: sashiko-bot@xxxxxxxxxx
> Closes: https://lore.kernel.org/all/20260705114746.1485F1F000E9@xxxxxxxxxxxxxxx/
> Reviewed-by: David Lechner <dlechner@xxxxxxxxxxxx>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
Let's hold off on this for now. Whilst it is technically correct today I'm
looking into ensuring that we never need this. The only error case
today is actually returning 0 which in practice is an error.
> ---
> drivers/iio/dac/ad5696-i2c.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
> index 279309329b64..551b200bfe14 100644
> --- a/drivers/iio/dac/ad5696-i2c.c
> +++ b/drivers/iio/dac/ad5696-i2c.c
> @@ -7,6 +7,7 @@
> * Copyright 2018 Analog Devices Inc.
> */
>
> +#include <linux/array_size.h>
> #include <linux/errno.h>
> #include <linux/i2c.h>
> #include <linux/mod_devicetable.h>
> @@ -39,9 +40,11 @@ static int ad5686_i2c_read(struct ad5686_state *st, u8 addr)
> AD5686_ADDR(addr) |
> 0x00);
>
> - ret = i2c_transfer(i2c->adapter, msg, 2);
> + ret = i2c_transfer(i2c->adapter, msg, ARRAY_SIZE(msg));
> if (ret < 0)
> return ret;
> + if (ret != ARRAY_SIZE(msg))
> + return -EIO;
>
> return be16_to_cpu(st->data[0].d16);
> }
>