[PATCH] staging: iio: adt7316: Add error handling to adt7316_spi_probe()

From: Maxwell Doose

Date: Sun Apr 26 2026 - 16:50:55 EST


Currently, the return values of the adt7316_spi_write() calls in
adt7316_spi_probe() are unchecked. Add error handling to return early
and pass on the error code if we receive an error from
adt7316_spi_write().

While at it, move all three adt7316_spi_write() calls inside a for loop
to condense the logic.

Signed-off-by: Maxwell Doose <m32285159@xxxxxxxxx>
---
drivers/staging/iio/addac/adt7316-spi.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
index f91325d11394..ffd1dae8d1b1 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,12 @@ 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);
+ /* Check for errors, if we get an error, return early */
+ if (ret < 0)
+ return ret;
+ }

return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias);
}
--
2.53.0