mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Siqi Chen <chensiqi@uniontech.com>
To: nish.malpani25@gmail.com, jic23@kernel.org
Cc: nuno.sa@analog.com, Michael.Hennerich@analog.com,
	dlechner@baylibre.com, andy@kernel.org,
	linux-iio@vger.kernel.org, linux@analog.com,
	linux-kernel@vger.kernel.org, Siqi Chen <chensiqi@uniontech.com>
Subject: [PATCH] iio: gyro: adxrs290: propagate chip ID read errors
Date: Thu, 19 Nov 2026 11:07:09 +0800	[thread overview]
Message-ID: <20261119030709.3792433-1-chensiqi@uniontech.com> (raw)

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.

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.

Fixes: 2c8920fff145 ("iio: gyro: Add driver support for ADXRS290")
Signed-off-by: Siqi Chen <chensiqi@uniontech.com>
---
 drivers/iio/gyro/adxrs290.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
index b61cc81122a6..eb3306215217 100644
--- a/drivers/iio/gyro/adxrs290.c
+++ b/drivers/iio/gyro/adxrs290.c
@@ -604,7 +604,7 @@ static int adxrs290_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 	struct adxrs290_state *st;
 	u8 val, val2;
-	int ret;
+	int id, ret;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (!indio_dev)
@@ -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);
+	id = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_ADI_ID));
+	if (id < 0)
+		return dev_err_probe(&spi->dev, id, "failed to read ADI ID\n");
+	if (id != ADXRS290_ADI_ID) {
+		dev_err(&spi->dev, "Wrong ADI ID 0x%02x\n", id);
 		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);
+	id = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_MEMS_ID));
+	if (id < 0)
+		return dev_err_probe(&spi->dev, id, "failed to read MEMS ID\n");
+	if (id != ADXRS290_MEMS_ID) {
+		dev_err(&spi->dev, "Wrong MEMS ID 0x%02x\n", id);
 		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);
+	id = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_DEV_ID));
+	if (id < 0)
+		return dev_err_probe(&spi->dev, id, "failed to read DEV ID\n");
+	if (id != ADXRS290_DEV_ID) {
+		dev_err(&spi->dev, "Wrong DEV ID 0x%02x\n", id);
 		return -ENODEV;
 	}
 

base-commit: 903941a9b06ae445c70646ab061b604c2dea17d3
-- 
2.20.1


                 reply	other threads:[~2026-11-19  3:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119030709.3792433-1-chensiqi@uniontech.com \
    --to=chensiqi@uniontech.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=nish.malpani25@gmail.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®