* [PATCH v2] iio: imu: bmi323: check i2c_transfer() return value
@ 2026-11-20 2:21 Siqi Chen
0 siblings, 0 replies; only message in thread
From: Siqi Chen @ 2026-11-20 2:21 UTC (permalink / raw)
To: jagathjog1996, jic23
Cc: crofts, dlechner, nuno.sa, andy, linux-iio, linux-kernel
i2c_transfer() returns the number of messages transferred or a negative
error code. The BMI323 I2C read path only checks for negative values and
maps all errors to -EIO.
If only the register-address message is transferred, the function copies
data from the receive buffer and reports success even though the read
message was not completed.
Require both messages to be transferred, preserve negative error codes,
and return -EIO for a short transfer.
OpenCode was used to identify the issue and draft the code and changelog.
Fixes: 8a636db3aa57 ("iio: imu: Add driver for BMI323 IMU")
Signed-off-by: Siqi Chen <chensiqi@uniontech.com>
---
Changes in v2:
- Split the transfer error and short-transfer checks for readability.
- Move testing information below the separator.
Compile-tested with CONFIG_BMI323_I2C=m using:
make O=/tmp/opencode/linux-build-bmi323 W=1 \
drivers/iio/imu/bmi323/bmi323_i2c.o
No hardware or I2C fault-injection testing was performed.
Link to v1:
https://lore.kernel.org/r/20261119070837.3844364-1-chensiqi@uniontech.com
drivers/iio/imu/bmi323/bmi323_i2c.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/imu/bmi323/bmi323_i2c.c b/drivers/iio/imu/bmi323/bmi323_i2c.c
index e025c88c30b4..27eddd1346d0 100644
--- a/drivers/iio/imu/bmi323/bmi323_i2c.c
+++ b/drivers/iio/imu/bmi323/bmi323_i2c.c
@@ -41,6 +41,8 @@ static int bmi323_regmap_i2c_read(void *context, const void *reg_buf,
ret = i2c_transfer(priv->i2c->adapter, msgs, ARRAY_SIZE(msgs));
if (ret < 0)
+ return ret;
+ if (ret != ARRAY_SIZE(msgs))
return -EIO;
memcpy(val_buf, priv->i2c_rx_buffer + BMI323_I2C_DUMMY, val_size);
base-commit: c1b99c6982dccade0199879966a2d97f27a0a110
--
2.20.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 2:22 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:21 [PATCH v2] iio: imu: bmi323: check i2c_transfer() return value 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®