* [PATCH 0/2] iio: health: max30102: fifo_ready() rename and I2C error propagation
@ 2026-11-27 18:26 Marco Chen
2026-11-27 18:26 ` [PATCH 1/2] iio: health: max30102: rename fifo_count() to fifo_ready() Marco Chen
2026-11-27 18:26 ` [PATCH 2/2] iio: health: max30102: propagate I2C read errors Marco Chen
0 siblings, 2 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 18:26 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, pmeerw, matt, linux-iio, linux-kernel, skhan,
linux-kernel-mentees
Patch 1 follows up on Jonathan's comment on the NULL-dereference fix
and patch 2 returns the actual I2C error from max30102_read_measurement().
All patches were tested on a Raspberry Pi 4 running the IIO subsystem tree
testing branch with the max30102. The module was reloaded and buffered data
was correctly read, with no errors.
Marco Chen (2):
iio: health: max30102: rename fifo_count() to fifo_ready()
iio: health: max30102: propagate I2C read errors
drivers/iio/health/max30102.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
base-commit: 39508411b82d4dc29dd245bb471ec9ecc1111c9d
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] iio: health: max30102: rename fifo_count() to fifo_ready()
2026-11-27 18:26 [PATCH 0/2] iio: health: max30102: fifo_ready() rename and I2C error propagation Marco Chen
@ 2026-11-27 18:26 ` Marco Chen
2026-11-27 18:26 ` [PATCH 2/2] iio: health: max30102: propagate I2C read errors Marco Chen
1 sibling, 0 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 18:26 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, pmeerw, matt, linux-iio, linux-kernel, skhan,
linux-kernel-mentees
The max30102_fifo_count() function does not count anything. It only
reports whether the FIFO_RDY bit is set, or a negative error value.
Rename max30102_fifo_count() to max30102_fifo_ready() and make it return
a bool. A failed status read returns false, which the handler already
treats as no data being available.
With a bool, the use of cnt in max30102_interrupt_handler() is no longer
needed, and a do/while loop can re-check the status after each sample.
The sequence of status and FIFO reads is the same as before.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Marco Chen <marcochen.dev@gmail.com>
---
Follow-up to Jonathan's comment on v2 of the NULL-dereference fix from
a few months ago
https://lore.kernel.org/linux-iio/20260805015826.2b558119@jic23-huawei/#R
Thank you.
drivers/iio/health/max30102.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index aee96167f01e..a553c0e011e0 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -235,20 +235,17 @@ static const struct iio_buffer_setup_ops max30102_buffer_setup_ops = {
.predisable = max30102_buffer_predisable,
};
-static inline int max30102_fifo_count(struct max30102_data *data)
+static inline bool max30102_fifo_ready(struct max30102_data *data)
{
unsigned int val;
int ret;
ret = regmap_read(data->regmap, MAX30102_REG_INT_STATUS, &val);
if (ret)
- return ret;
+ return false;
/* FIFO has one sample slot left */
- if (val & MAX30102_REG_INT_STATUS_FIFO_RDY)
- return 1;
-
- return 0;
+ return val & MAX30102_REG_INT_STATUS_FIFO_RDY;
}
#define MAX30102_COPY_DATA(i) \
@@ -291,10 +288,9 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private)
struct iio_dev *indio_dev = private;
struct max30102_data *data = iio_priv(indio_dev);
unsigned int measurements;
- int ret, cnt;
+ int ret;
- cnt = max30102_fifo_count(data);
- if (cnt <= 0)
+ if (!max30102_fifo_ready(data))
return IRQ_HANDLED;
measurements = bitmap_weight(indio_dev->active_scan_mask,
@@ -302,14 +298,13 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private)
mutex_lock(&data->lock);
- while (cnt || (cnt = max30102_fifo_count(data)) > 0) {
+ do {
ret = max30102_read_measurement(data, measurements);
if (ret)
break;
iio_push_to_buffers(data->indio_dev, data->processed_buffer);
- cnt--;
- }
+ } while (max30102_fifo_ready(data));
mutex_unlock(&data->lock);
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] iio: health: max30102: propagate I2C read errors
2026-11-27 18:26 [PATCH 0/2] iio: health: max30102: fifo_ready() rename and I2C error propagation Marco Chen
2026-11-27 18:26 ` [PATCH 1/2] iio: health: max30102: rename fifo_count() to fifo_ready() Marco Chen
@ 2026-11-27 18:26 ` Marco Chen
1 sibling, 0 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 18:26 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, pmeerw, matt, linux-iio, linux-kernel, skhan,
linux-kernel-mentees
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 18:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 18:26 [PATCH 0/2] iio: health: max30102: fifo_ready() rename and I2C error propagation Marco Chen
2026-11-27 18:26 ` [PATCH 1/2] iio: health: max30102: rename fifo_count() to fifo_ready() Marco Chen
2026-11-27 18:26 ` [PATCH 2/2] iio: health: max30102: propagate I2C read errors Marco 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®