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 4/5] iio: buffer: ensure repeat alignment is a power of two
Date: Sat, 07 Mar 2026 19:44:12 -0600 [thread overview]
Message-ID: <20260307-iio-fix-timestamp-alignment-v2-4-d1d48fbadbbf@baylibre.com> (raw)
In-Reply-To: <20260307-iio-fix-timestamp-alignment-v2-0-d1d48fbadbbf@baylibre.com>
Use roundup_pow_of_two() in the calculation of iio_storage_bytes_for_si()
when scan_type->repeat > 1 to ensure that the size is a power of two.
storagebits is always going to be a power of two bytes, so we only need
to apply this to the repeat factor. The storage size is also used for
alignment, and we want to ensure that all alignments are a power of two.
The only repeat in use in the kernel currently is for quaternions, which
have a repeat of 4, so this does not change the result for existing
users.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
v2 changes: new patch
In v1, Nuno made the point that if the size isn't a power of two, then
the alignment won't be a power of two either. And this could cause
unexpected problems regarding alignment in general.
This will affect the work Francesco is doing with IIO_MOD_QUATERNION_AXIS
which will have a repeat of 3, so this is a good time to think about this.
---
drivers/iio/industrialio-buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index ecfe0c9740e2..c38da24561c0 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -748,7 +748,7 @@ static int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
bytes = scan_type->storagebits / 8;
if (scan_type->repeat > 1)
- bytes *= scan_type->repeat;
+ bytes *= roundup_pow_of_two(scan_type->repeat);
return bytes;
}
--
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 ` [PATCH v2 2/5] iio: buffer: check return value of iio_compute_scan_bytes() David Lechner
2026-03-08 1:44 ` [PATCH v2 3/5] iio: buffer: cache timestamp offset in scan buffer David Lechner
2026-03-08 1:44 ` David Lechner [this message]
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-4-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