drivers/staging/iio/addac/adt7316-spi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
The probe function issues three SPI writes to switch the device
from the default I2C protocol to SPI protocol, but ignores their
return values.
Add error checking and emit a warning if any of these writes fail,
to improve error visibility without changing existing behavior.
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
drivers/staging/iio/addac/adt7316-spi.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
index f91325d11394..25b7772bd05f 100644
--- a/drivers/staging/iio/addac/adt7316-spi.c
+++ b/drivers/staging/iio/addac/adt7316-spi.c
@@ -98,6 +98,7 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
.multi_read = adt7316_spi_multi_read,
.multi_write = adt7316_spi_multi_write,
};
+ int i, ret;
/* don't exceed max specified SPI CLK frequency */
if (spi_dev->max_speed_hz > ADT7316_SPI_MAX_FREQ_HZ) {
@@ -107,9 +108,11 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
}
/* switch from default I2C protocol to SPI protocol */
- adt7316_spi_write(spi_dev, 0, 0);
- adt7316_spi_write(spi_dev, 0, 0);
- adt7316_spi_write(spi_dev, 0, 0);
+ for (i = 0; i < 3; i++) {
+ ret = adt7316_spi_write(spi_dev, 0, 0);
+ if (ret)
+ dev_warn(&spi_dev->dev, "SPI init write %d failed: %d\n", i, ret);
+ }
return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias);
}
--
2.34.1
On Sat, 2026-05-09 at 08:26 +0000, Hungyu Lin wrote:
> The probe function issues three SPI writes to switch the device
> from the default I2C protocol to SPI protocol, but ignores their
> return values.
>
> Add error checking and emit a warning if any of these writes fail,
> to improve error visibility without changing existing behavior.
>
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
Hi Hungyu,
Small comment from me. With that addressed:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> drivers/staging/iio/addac/adt7316-spi.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/iio/addac/adt7316-spi.c
> b/drivers/staging/iio/addac/adt7316-spi.c
> index f91325d11394..25b7772bd05f 100644
> --- a/drivers/staging/iio/addac/adt7316-spi.c
> +++ b/drivers/staging/iio/addac/adt7316-spi.c
> @@ -98,6 +98,7 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
> .multi_read = adt7316_spi_multi_read,
> .multi_write = adt7316_spi_multi_write,
> };
> + int i, ret;
>
> /* don't exceed max specified SPI CLK frequency */
> if (spi_dev->max_speed_hz > ADT7316_SPI_MAX_FREQ_HZ) {
> @@ -107,9 +108,11 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
> }
>
> /* switch from default I2C protocol to SPI protocol */
> - adt7316_spi_write(spi_dev, 0, 0);
> - adt7316_spi_write(spi_dev, 0, 0);
> - adt7316_spi_write(spi_dev, 0, 0);
> + for (i = 0; i < 3; i++) {
> + ret = adt7316_spi_write(spi_dev, 0, 0);
> + if (ret)
> + dev_warn(&spi_dev->dev, "SPI init write %d failed: %d\n",
> i, ret);
> + }
Hmm this is a bit useless no :)? Agree we should check for error codes but we should
bail in case of errors. You can also mention the loop() introduction.
- Nuno Sá
>
> return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias);
> }
© 2016 - 2026 Red Hat, Inc.