mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iio: gyro: adxrs290: propagate chip ID read errors
@ 2026-11-20  2:57 Siqi Chen
  0 siblings, 0 replies; only message in thread
From: Siqi Chen @ 2026-11-20  2:57 UTC (permalink / raw)
  To: nish.malpani25, jic23
  Cc: crofts, nuno.sa, Michael.Hennerich, dlechner, andy, linux-iio,
	linux, linux-kernel

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")
Signed-off-by: Siqi Chen <chensiqi@uniontech.com>
---
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/20261119030709.3792433-1-chensiqi@uniontech.com

 drivers/iio/gyro/adxrs290.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
index b61cc81122a6..2e0bebf2ed26 100644
--- a/drivers/iio/gyro/adxrs290.c
+++ b/drivers/iio/gyro/adxrs290.c
@@ -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
-- 
2.20.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20  2:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  2:57 [PATCH v2] iio: gyro: adxrs290: propagate chip ID read errors Siqi Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®