Skip to contentSkip to conversation

iio: gyro: adxrs290: propagate chip ID read errors

PATCH In review Siqi Chen 3 participants 3 messages Nov 20 – Nov 21

Subsystems (3)
lore
Share & tools
lore

Siqi Chen

author
#0 lore raw

PATCH v2 1/1 iio: gyro: adxrs290: propagate chip ID read errors

spi_w8r8() returns either an unsigned 8-bit value or a negative error. The probe function stores its return value in a u8, truncating errors and treating them as unexpected chip IDs. Consequently, an SPI transfer failure is reported as -ENODEV instead of the actual error.

Store each result in an int and return negative errors before validating the chip IDs.

Fixes 2c8920fff145 ("iio: gyro: Add driver support for ADXRS290")

---
Changes in v2:
- Reuse ret for chip ID reads instead of adding a separate variable.
- Log chip ID mismatches at info level.
- Move the OpenCode disclosure and testing information below the separator.

OpenCode was used to identify the issue and draft the code and changelog.

Compile-tested with CONFIG_ADXRS290=m using:

  make O=/tmp/opencode/linux-build-adxrs290 W=1 \
       drivers/iio/gyro/adxrs290.o

No hardware or SPI fault-injection testing was performed.

Link to v1:
https://lore.kernel.org/r/[email protected]

 drivers/iio/gyro/adxrs290.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/iio/gyro/adxrs290.c +15 -9
index b61cc81122a6..2e0bebf2ed26 100644
@@ -622,21 +622,27 @@ static int adxrs290_probe(struct spi_device *spi)
 
 	mutex_init(&st->lock);
 
-	val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_ADI_ID));
-	if (val != ADXRS290_ADI_ID) {
-		dev_err(&spi->dev, "Wrong ADI ID 0x%02x\n", val);
+	ret = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_ADI_ID));
+	if (ret < 0)
+		return dev_err_probe(&spi->dev, ret, "failed to read ADI ID\n");
+	if (ret != ADXRS290_ADI_ID) {
+		dev_info(&spi->dev, "Wrong ADI ID 0x%02x\n", ret);
 		return -ENODEV;
 	}
 
-	val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_MEMS_ID));
-	if (val != ADXRS290_MEMS_ID) {
-		dev_err(&spi->dev, "Wrong MEMS ID 0x%02x\n", val);
+	ret = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_MEMS_ID));
+	if (ret < 0)
+		return dev_err_probe(&spi->dev, ret, "failed to read MEMS ID\n");
+	if (ret != ADXRS290_MEMS_ID) {
+		dev_info(&spi->dev, "Wrong MEMS ID 0x%02x\n", ret);
 		return -ENODEV;
 	}
 
-	val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_DEV_ID));
-	if (val != ADXRS290_DEV_ID) {
-		dev_err(&spi->dev, "Wrong DEV ID 0x%02x\n", val);
+	ret = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_DEV_ID));
+	if (ret < 0)
+		return dev_err_probe(&spi->dev, ret, "failed to read DEV ID\n");
+	if (ret != ADXRS290_DEV_ID) {
+		dev_info(&spi->dev, "Wrong DEV ID 0x%02x\n", ret);
 		return -ENODEV;
 	}
 

base-commit: 903941a9b06ae445c70646ab061b604c2dea17d3

Signature · 1 line
2.20.1
#1 lore raw
Quoted 7 lines · Siqi Chen

spi_w8r8() returns either an unsigned 8-bit value or a negative error. The probe function stores its return value in a u8, truncating errors and treating them as unexpected chip IDs. Consequently, an SPI transfer failure is reported as -ENODEV instead of the actual error.

Store each result in an int and return negative errors before validating the chip IDs.

...

Quoted 2 lines

- Move the OpenCode disclosure and testing information below the separator.

It's interesting that the other patch without this amendment was sent just a half an hour before this one. If you get a comment against one, check all the rest (at least for the same subsystem). Always.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
Quoted 9 lines · On Fri, 20 Nov 2026 11:40:18 +0200 Andy Shevchenko…
Quoted 7 lines · Siqi Chen

spi_w8r8() returns either an unsigned 8-bit value or a negative error. The probe function stores its return value in a u8, truncating errors and treating them as unexpected chip IDs. Consequently, an SPI transfer failure is reported as -ENODEV instead of the actual error.

Store each result in an int and return negative errors before validating the chip IDs.

Quoted 9 lines

...

Quoted 2 lines

- Move the OpenCode disclosure and testing information below the separator.

It's interesting that the other patch without this amendment was sent just a half an hour before this one. If you get a comment against one, check all the rest (at least for the same subsystem). Always.

Applied to the testing branch of iio.git.

Thanks,

Jonathan