From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 07/13] iio: adc: ad4134: Support buffered data read
Date: Wed, 02 Sep 2026 17:38:57 +0000 [thread overview]
Message-ID: <20260902173857.7EAC41F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <b44fc7cd06c295781e2144ae3586eac80b23bea9.1788368334.git.marcelo.schmitt@analog.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] The trigger handler loops up to masklength instead of the physical channel count, causing an out-of-bounds array write and issuing an invalid SPI read for the software timestamp channel.
- [High] The scan buffer is undersized for captures with a timestamp, causing `iio_push_to_buffers_with_ts()` to always fail with `-ENOSPC`.
- [High] Adding the timestamp channel breaks single-shot reads by causing `ad4134_data_read()` to execute 5 SPI transfers instead of 4.
- [High] Removing DMA alignment from `rx_buf` and `tx_buf` causes them to share a cacheline with `st->scan`, leading to potential DMA data corruption.
- [Low] Buffer compaction logic uses `memcpy` with identically overlapping memory regions, triggering Undefined Behavior.
--
commit 923506d627d1a5bd978cd92880886f1fdb5f8bfd
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>
Date: Wed Sep 2 17:23:42 2026 +0000
iio: adc: ad4134: Support buffered data read
This commit adds buffered data capture support for the AD4134, triggered by
an IIO trigger device, and introduces a software timestamp channel. It also
enforces direct access mode for single-read operations to prevent
interference with buffered reads.
> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index a1474316e330d..0751b89dec8f3 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c
[ ... ]
> @@ -133,6 +144,7 @@ static const struct iio_chan_spec ad4134_chan_set[] = {
> AD4134_CHANNEL(1),
> AD4134_CHANNEL(2),
> AD4134_CHANNEL(3),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> };
[Severity: High]
Will adding this timestamp channel break single-shot reads?
Looking at ad4134_data_read(), the loop iterating over this set uses
ARRAY_SIZE(ad4134_chan_set):
for (i = 0; i < ARRAY_SIZE(ad4134_chan_set); i++) {
ret = spi_write_then_read(...)
Since the array size is now 5, this will execute 5 times instead of the
4 times expected by the hardware. Could this clock out invalid data and
disrupt the ADC's data framing state machine?
> struct ad4134_state {
> @@ -151,7 +163,8 @@ struct ad4134_state {
> * DMA (thus cache coherency maintenance) requires the transfer buffers
> * to live in their own cache lines.
> */
> - u8 rx_buf[AD4134_SPI_MAX_XFER_LEN] __aligned(IIO_DMA_MINALIGN);
> + u32 scan[AD4134_NUM_CHANNELS] __aligned(IIO_DMA_MINALIGN);
> + u8 rx_buf[AD4134_SPI_MAX_XFER_LEN];
> u8 tx_buf[AD4134_SPI_MAX_XFER_LEN];
> };
[Severity: High]
Does the removal of the __aligned(IIO_DMA_MINALIGN) attribute from rx_buf
and tx_buf risk silent DMA data corruption?
Because scan is only 16 bytes (4 channels * 4 bytes), rx_buf and tx_buf
could now share the same cacheline. A concurrent debugfs/sysfs register
read/write could cause cacheline invalidation during a DMA unmap, resulting
in lost CPU writes to the scan buffer during a triggered capture.
Also, is the scan buffer large enough to hold the timestamp? The scan buffer
allocates 16 bytes, but the naturally-aligned 64-bit IIO timestamp appended
by IIO will require an additional 8 bytes of space.
[ ... ]
> @@ -336,6 +349,36 @@ static const struct regmap_config ad4134_regmap_config = {
> .max_register = AD4134_CH_VREG(ARRAY_SIZE(ad4134_chan_set)),
> };
>
> +static irqreturn_t ad4134_trigger_handler(int irq, void *p)
> +{
> + struct iio_poll_func *pf = p;
> + struct iio_dev *indio_dev = pf->indio_dev;
> + struct ad4134_state *st = iio_priv(indio_dev);
> + unsigned int i = 0;
> + int ret;
> +
> + gpiod_set_value_cansleep(st->odr_gpio, 1);
> + fsleep(1);
> + gpiod_set_value_cansleep(st->odr_gpio, 0);
> +
> + for (unsigned int ch = 0; ch < iio_get_masklength(indio_dev); ch++) {
> + ret = spi_write_then_read(st->spi, NULL, 0, &st->scan[ch],
> + BITS_TO_BYTES(AD4134_CHAN_PRECISION_BITS));
[Severity: High]
When the software timestamp channel is enabled, does iio_get_masklength()
evaluate to 5?
If so, this loop will exceed the hardware channel count (4) and write out of
bounds to st->scan[4]. This could directly corrupt the adjacent rx_buf field
and issue an invalid SPI read to the device.
> + if (ret)
> + goto err_out;
> +
> + if (test_bit(ch, indio_dev->active_scan_mask))
> + memcpy(&st->scan[i++], &st->scan[ch], sizeof(st->scan[ch]));
[Severity: Low]
Is it safe to use memcpy() here when the source and destination overlap?
When ch == i, the memory regions overlap identically. Since memcpy()
restricts overlapping pointers, this can trigger undefined behavior.
> + }
> +
> + iio_push_to_buffers_with_ts(indio_dev, &st->scan, sizeof(st->scan),
> + pf->timestamp);
[Severity: High]
Does this fail with -ENOSPC when the timestamp channel is enabled?
The length passed here is sizeof(st->scan), which is 16 bytes. The IIO core
requires 24 bytes (16 bytes data + 8 bytes timestamp) for pushing captures
with a timestamp, which could cause every sample to be rejected and dropped.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788368334.git.marcelo.schmitt@analog.com?part=7
next prev parent reply other threads:[~2026-09-02 17:38 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 17:21 [PATCH v1 00/13] iio: adc: ad4134: Enable greater sample rate data capture Marcelo Schmitt
2026-09-02 17:21 ` [PATCH v1 01/13] iio: Fix typo in vendor name Marcelo Schmitt
2026-09-03 6:22 ` Andy Shevchenko
2026-09-04 19:41 ` Marcelo Schmitt
2026-09-05 7:40 ` Andy Shevchenko
2026-09-05 7:41 ` Andy Shevchenko
2026-09-02 17:21 ` [PATCH v1 02/13] iio: adc: ad4134: Drop import to empty name space Marcelo Schmitt
2026-09-02 17:22 ` [PATCH v1 03/13] iio: adc: ad4134: Update include list to comply with IWYU principles Marcelo Schmitt
2026-09-02 17:40 ` sashiko-bot
2026-09-03 6:26 ` Andy Shevchenko
2026-09-02 17:22 ` [PATCH v1 04/13] iio: adc: ad4134: Serialize single-read operations Marcelo Schmitt
2026-09-03 6:27 ` Andy Shevchenko
2026-09-06 18:50 ` Jonathan Cameron
2026-09-02 17:23 ` [PATCH v1 05/13] iio: adc: ad4134: Run shorter transfers when CRC is disabled Marcelo Schmitt
2026-09-02 17:42 ` sashiko-bot
2026-09-02 17:23 ` [PATCH v1 06/13] iio: adc: ad4134: Add support for digital filter type selection Marcelo Schmitt
2026-09-03 6:31 ` Andy Shevchenko
2026-09-02 17:23 ` [PATCH v1 07/13] iio: adc: ad4134: Support buffered data read Marcelo Schmitt
2026-09-02 17:38 ` sashiko-bot [this message]
2026-09-02 17:24 ` [PATCH v1 08/13] dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode Marcelo Schmitt
2026-09-02 17:46 ` sashiko-bot
2026-09-03 18:14 ` Conor Dooley
2026-09-04 20:47 ` Marcelo Schmitt
2026-09-04 22:06 ` Marcelo Schmitt
2026-09-06 19:26 ` Jonathan Cameron
2026-09-09 15:17 ` Marcelo Schmitt
2026-09-07 17:52 ` Conor Dooley
2026-09-10 22:19 ` Marcelo Schmitt
2026-09-06 19:15 ` Jonathan Cameron
2026-09-02 17:24 ` [PATCH v1 09/13] iio: adc: ad4134: Support SPI 4-wire mode Marcelo Schmitt
2026-09-02 17:46 ` sashiko-bot
2026-09-03 6:39 ` Andy Shevchenko
2026-09-02 17:24 ` [PATCH v1 10/13] dt-bindings: iio: adc: adi,ad4134: Document PWM usage Marcelo Schmitt
2026-09-04 15:53 ` Conor Dooley
2026-09-02 17:25 ` [PATCH v1 11/13] dt-bindings: iio: adc: adi,ad4134: Add high data throughput example Marcelo Schmitt
2026-09-02 17:39 ` sashiko-bot
2026-09-02 17:25 ` [PATCH v1 12/13] iio: adc: ad4134: Support high-speed data capture Marcelo Schmitt
2026-09-02 17:49 ` sashiko-bot
2026-09-03 7:00 ` Andy Shevchenko
2026-09-02 17:25 ` [PATCH v1 13/13] Docs: iio: Add AD4134 Marcelo Schmitt
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=20260902173857.7EAC41F00AC4@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.