Skip to contentSkip to conversation

staging: iio: addac: adt7316: check SPI write errors in probe

PATCH Superseded Hungyu Lin 2 participants 2 messages May 9

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 staging: iio: addac: adt7316: check SPI write errors in probe

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.

---
 drivers/staging/iio/addac/adt7316-spi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/iio/addac/adt7316-spi.c +6 -3
index f91325d11394..25b7772bd05f 100644
@@ -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);
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Hungyu Lin

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.

---

Hi Hungyu,

Small comment from me. With that addressed:

Quoted 28 lines

 drivers/staging/iio/addac/adt7316-spi.c | 9 ++++++---

 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/iio/addac/adt7316-spi.c +1 -0
index f91325d11394..25b7772bd05f 100644
@@ -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) {

drivers/staging/iio/addac/adt7316-spi.c +0 -0
@@ -107,9 +108,11 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
  	}


  /* switch from default I2C protocol to SPI protocol */

drivers/staging/iio/addac/adt7316-spi.c +4 -3
-	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);

drivers/staging/iio/addac/adt7316-spi.c static int adt7316_spi_probe(struct spi_device *spi_dev) · line 115

Quoted 1 line
drivers/staging/iio/addac/adt7316-spi.c +1 -0
+	}

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á

Quoted 3 lines


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