From: Marco Chen <marcochen.dev@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
pmeerw@pmeerw.net, matt@ranostay.sg, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linux.dev
Subject: [PATCH 2/2] iio: health: max30102: propagate I2C read errors
Date: Fri, 27 Nov 2026 13:26:36 -0500 [thread overview]
Message-ID: <20261127182636.83803-3-marcochen.dev@gmail.com> (raw)
In-Reply-To: <20261127182636.83803-1-marcochen.dev@gmail.com>
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
prev parent reply other threads:[~2026-11-27 18:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20261127182636.83803-3-marcochen.dev@gmail.com \
--to=marcochen.dev@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@ranostay.sg \
--cc=nuno.sa@analog.com \
--cc=pmeerw@pmeerw.net \
--cc=skhan@linuxfoundation.org \
/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®