[PATCH 2/2] iio: health: max30102: propagate I2C read errors
From: Marco Chen
Date: Fri Nov 27 2026 - 13:26:50 EST
max30102_read_measurement() returns -EINVAL for every failed I2C read,
discarding the error code returned by i2c_smbus_read_i2c_block_data().
Return that error code instead. While at it, move the existing length
check above the copy as well, so both checks happen before the data is
used. The only caller, max30102_interrupt_handler(), stops reading on
any error, so behavior seen by userspace is unchanged.
Signed-off-by: Marco Chen <marcochen.dev@xxxxxxxxx>
---
The I2C error path was found by inspection, but was not actually tested
on hardware.
Additionally, checkpatch.pl --strict reports "foo * bar" for the
multiplication in the length check, but I think this is a false positive.
Not sure how to handle it though.
Thank you.
drivers/iio/health/max30102.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index a553c0e011e0..829e8b18512d 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -264,6 +264,11 @@ static int max30102_read_measurement(struct max30102_data *data,
measurements *
MAX30102_REG_FIFO_DATA_BYTES,
buffer);
+ if (ret < 0)
+ return ret;
+
+ if (ret != measurements * MAX30102_REG_FIFO_DATA_BYTES)
+ return -EINVAL;
switch (measurements) {
case 3:
@@ -279,8 +284,7 @@ static int max30102_read_measurement(struct max30102_data *data,
return -EINVAL;
}
- return (ret == measurements * MAX30102_REG_FIFO_DATA_BYTES) ?
- 0 : -EINVAL;
+ return 0;
}
static irqreturn_t max30102_interrupt_handler(int irq, void *private)
--
2.56.1