From: David Lechner <dlechner@baylibre.com>
To: "Jiri Kosina" <jikos@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Lars Möllendorf" <lars.moellendorf@plating.de>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Lixu Zhang <lixu.zhang@intel.com>,
Francesco Lavra <flavra@baylibre.com>,
linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
David Lechner <dlechner@baylibre.com>
Subject: [PATCH v2 2/5] iio: buffer: check return value of iio_compute_scan_bytes()
Date: Sat, 07 Mar 2026 19:44:10 -0600 [thread overview]
Message-ID: <20260307-iio-fix-timestamp-alignment-v2-2-d1d48fbadbbf@baylibre.com> (raw)
In-Reply-To: <20260307-iio-fix-timestamp-alignment-v2-0-d1d48fbadbbf@baylibre.com>
Check return value of iio_compute_scan_bytes() as it can return an
error.
The result is moved to an output parameter while we are touching this
as we will need to add a second output parameter in a later change.
The return type of iio_buffer_update_bytes_per_datum() also had to be
changed to propagate the error.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/industrialio-buffer.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index f15a180dc49e..4e413b4bb073 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -762,7 +762,8 @@ static int iio_storage_bytes_for_timestamp(struct iio_dev *indio_dev)
}
static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
- const unsigned long *mask, bool timestamp)
+ const unsigned long *mask, bool timestamp,
+ unsigned int *scan_bytes)
{
unsigned int bytes = 0;
int length, i, largest = 0;
@@ -788,8 +789,9 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
largest = max(largest, length);
}
- bytes = ALIGN(bytes, largest);
- return bytes;
+ *scan_bytes = ALIGN(bytes, largest);
+
+ return 0;
}
static void iio_buffer_activate(struct iio_dev *indio_dev,
@@ -834,18 +836,23 @@ static int iio_buffer_disable(struct iio_buffer *buffer,
return buffer->access->disable(buffer, indio_dev);
}
-static void iio_buffer_update_bytes_per_datum(struct iio_dev *indio_dev,
- struct iio_buffer *buffer)
+static int iio_buffer_update_bytes_per_datum(struct iio_dev *indio_dev,
+ struct iio_buffer *buffer)
{
unsigned int bytes;
+ int ret;
if (!buffer->access->set_bytes_per_datum)
- return;
+ return 0;
- bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
- buffer->scan_timestamp);
+ ret = iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
+ buffer->scan_timestamp, &bytes);
+ if (ret)
+ return ret;
buffer->access->set_bytes_per_datum(buffer, bytes);
+
+ return 0;
}
static int iio_buffer_request_update(struct iio_dev *indio_dev,
@@ -853,7 +860,10 @@ static int iio_buffer_request_update(struct iio_dev *indio_dev,
{
int ret;
- iio_buffer_update_bytes_per_datum(indio_dev, buffer);
+ ret = iio_buffer_update_bytes_per_datum(indio_dev, buffer);
+ if (ret)
+ return ret;
+
if (buffer->access->request_update) {
ret = buffer->access->request_update(buffer);
if (ret) {
@@ -896,6 +906,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,
struct iio_buffer *buffer;
bool scan_timestamp;
unsigned int modes;
+ int ret;
if (insert_buffer &&
bitmap_empty(insert_buffer->scan_mask, masklength)) {
@@ -983,8 +994,11 @@ static int iio_verify_update(struct iio_dev *indio_dev,
scan_mask = compound_mask;
}
- config->scan_bytes = iio_compute_scan_bytes(indio_dev,
- scan_mask, scan_timestamp);
+ ret = iio_compute_scan_bytes(indio_dev, scan_mask, scan_timestamp,
+ &config->scan_bytes);
+ if (ret)
+ return ret;
+
config->scan_mask = scan_mask;
config->scan_timestamp = scan_timestamp;
--
2.43.0
next prev parent reply other threads:[~2026-03-08 1:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 1:44 [PATCH v2 0/5] iio: buffer: fix timestamp alignment (in rare case) David Lechner
2026-03-08 1:44 ` [PATCH v2 1/5] iio: orientation: hid-sensor-rotation: add timestamp hack to not break userspace David Lechner
2026-03-14 12:18 ` Jonathan Cameron
2026-03-08 1:44 ` David Lechner [this message]
2026-03-08 1:44 ` [PATCH v2 3/5] iio: buffer: cache timestamp offset in scan buffer David Lechner
2026-03-08 1:44 ` [PATCH v2 4/5] iio: buffer: ensure repeat alignment is a power of two David Lechner
2026-03-08 1:44 ` [PATCH v2 5/5] iio: buffer: fix timestamp alignment when quaternion in scan David Lechner
2026-03-09 14:15 ` [PATCH v2 0/5] iio: buffer: fix timestamp alignment (in rare case) Nuno Sá
2026-04-12 14:20 ` Jonathan Cameron
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=20260307-iio-fix-timestamp-alignment-v2-2-d1d48fbadbbf@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=flavra@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=lars.moellendorf@plating.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=nuno.sa@analog.com \
--cc=srinivas.pandruvada@linux.intel.com \
/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®