[PATCH v2 1/5] iio: chemical: sgp40: Do not convert I2C errors to EIO
From: Jaakko Koivisto
Date: Mon Nov 02 2026 - 04:15:20 EST
Any negative error returned by i2c_master_send() in
sgp40_measure_resistance_raw() was caught by the
branch guarding against short sends, and the error
was subsequently replaced with -EIO.
Check for any negative errors first and propagate
the error without conversion.
Fixes: 1081b9d97152 ("iio: chemical: Add driver support for sgp40")
Signed-off-by: Jaakko Koivisto <jmatko@xxxxxx>
---
Tested by forcing i2c clock to ground. The resulting ETIMEDOUT and
EREMOTEIO are now correctly communicated to userspace instead of
converting to EIO.
drivers/iio/chemical/sgp40.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/chemical/sgp40.c b/drivers/iio/chemical/sgp40.c
index b2b5e32a9eb2..3a239fb6847f 100644
--- a/drivers/iio/chemical/sgp40.c
+++ b/drivers/iio/chemical/sgp40.c
@@ -187,6 +187,8 @@ static int sgp40_measure_resistance_raw(struct sgp40_data *data, u16 *resistance
mutex_unlock(&data->lock);
ret = i2c_master_send(client, (const char *)&tg, sizeof(tg));
+ if (ret < 0)
+ return ret;
if (ret != sizeof(tg)) {
dev_warn(data->dev, "i2c_master_send ret: %d sizeof: %zu\n", ret, sizeof(tg));
return -EIO;
--
2.56.0