Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v3 07/13] iio: adc: ad4134: Support buffered data read
Date: Tue, 29 Sep 2026 23:05:28 +0000	[thread overview]
Message-ID: <20260929230528.8861C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <095cea21f1a9fc39aa0a81b990e87c1046bb3dc9.1790719424.git.marcelo.schmitt@analog.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mm: concurrent use of shared DMA buffers st->rx_buf and st->tx_buf
- [High] spi: cs_off = true in triggered buffer breaks 4-wire mode communication
- [High] iio: ADC output frame resets due to looped SPI transfers
--

commit 29f8197d694e692f78d7a5142e0a389309c577b0
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>

    iio: adc: ad4134: Support buffered data read
    
    Enable users to run buffered data captures triggered by IIO trigger device.
    Add an IIO timestamp channel so each data scan is provided with measurement
    time information. Require single-read operations to be in IIO device direct
    access mode to prevent buffered and single-shot data captures to disrupt
    each other.

> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index 14996a0d1fe88..f0196126515e6 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c

[ ... ]

> @@ -333,6 +344,43 @@ static const struct regmap_config ad4134_regmap_config = {
>  	.max_register = AD4134_CH_VREG(ARRAY_SIZE(ad4134_chan_set) - 1),
>  };
>  
> +static irqreturn_t ad4134_trigger_handler(int irq, void *p)
> +{
> +	IIO_DECLARE_BUFFER_WITH_TS(u32, channels, AD4134_NUM_CHANNELS) = { };
> +	struct iio_poll_func *pf = p;
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct ad4134_state *st = iio_priv(indio_dev);
> +	struct spi_transfer xfer = {
> +		.rx_buf = st->rx_buf,

[Severity: High]
If userspace reads or writes ADC registers via debugfs while the triggered
buffer is running in minimum I/O mode (NO_CS), ad4134_debugfs_reg_access()
can run concurrently with ad4134_trigger_handler().

Because the trigger handler does not acquire any locks to protect the shared
DMA buffers, and while regmap acquires st->access_lock, this lock is
explicitly not held during buffer capture in NO_CS mode (as setup_ops is
NULL), both threads can use the shared st->rx_buf and st->tx_buf
simultaneously.

Does this concurrent use cause DMA buffer corruption, potential kernel panics
during concurrent DMA mappings, or incorrect data reads?

> +		.cs_off = true,

[Severity: High]
When the driver is configured in 4-wire mode (adi,spi-mode = "4-wire") and
falls back to the software trigger handler, this flag explicitly instructs
the SPI controller to leave the chip select line inactive (high) for the
duration of the transfer.

Since the AD4134 requires an active (low) chip select to frame the data in
4-wire mode, does this setting break 4-wire mode communication and prevent
the device from outputting valid sample data?

> +		.len = BITS_TO_BYTES(AD4134_CHAN_PRECISION_BITS),
> +	};
> +	int ret;
> +
> +	gpiod_set_value_cansleep(st->odr_gpio, 1);
> +	fsleep(1);
> +	gpiod_set_value_cansleep(st->odr_gpio, 0);
> +
> +	/* Execute transfers for all channels so the entire data frame is read. */
> +	for (int ch = 0, i = 0; ch < AD4134_NUM_CHANNELS; ch++) {
> +		ret = spi_sync_transfer(st->spi, &xfer, 1);

[Severity: High]
In 4-wire mode, the AD4134 resets its data output frame if the chip select
goes high or if the DCLK is idle for more than 250ns.

Does calling spi_sync_transfer() in a loop for each channel introduce
software delays far exceeding 250ns and toggle the CS line between calls?

Could this violate the device's continuous clocking and CS timing
requirements, causing the frame to reset on every iteration and reading
Channel 0 repeatedly instead of streaming consecutive channels?

Should a single bulk SPI transfer be used here instead of a loop?

> +		if (ret)
> +			goto out;
> +
> +		if (!test_bit(ch, indio_dev->active_scan_mask))
> +			continue;
> +
> +		channels[i++] = get_unaligned_be24(st->rx_buf);
> +	}
> +
> +	iio_push_to_buffers_with_ts(indio_dev, channels, sizeof(channels),
> +				    pf->timestamp);
> +
> +out:
> +	iio_trigger_notify_done(indio_dev->trig);
> +	return IRQ_HANDLED;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790719424.git.marcelo.schmitt@analog.com?part=7

  reply	other threads:[~2026-09-29 23:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 22:41 [PATCH v3 00/13] iio: adc: ad4134: Enable greater sample rate data capture Marcelo Schmitt
2026-09-29 22:42 ` [PATCH v3 01/13] iio: adc: ad4134: Adjust register map range Marcelo Schmitt
2026-09-29 22:42 ` [PATCH v3 02/13] iio: adc: ad4134: Sign extend sample data Marcelo Schmitt
2026-09-30  8:50   ` Joshua Crofts
2026-09-29 22:42 ` [PATCH v3 03/13] iio: adc: ad4134: Update include list to comply with IWYU principles Marcelo Schmitt
2026-09-29 22:43 ` [PATCH v3 04/13] iio: adc: ad4134: Serialize single-read operations Marcelo Schmitt
2026-09-29 22:52   ` sashiko-bot
2026-09-29 22:43 ` [PATCH v3 05/13] iio: adc: ad4134: Run shorter transfers when CRC is disabled Marcelo Schmitt
2026-09-29 22:43 ` [PATCH v3 06/13] iio: adc: ad4134: Add support for digital filter type selection Marcelo Schmitt
2026-09-29 22:44 ` [PATCH v3 07/13] iio: adc: ad4134: Support buffered data read Marcelo Schmitt
2026-09-29 23:05   ` sashiko-bot [this message]
2026-09-30 18:54     ` Marcelo Schmitt
2026-09-29 22:44 ` [PATCH v3 08/13] dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode Marcelo Schmitt
2026-09-29 23:02   ` sashiko-bot
2026-09-30 18:23     ` Marcelo Schmitt
2026-09-30 11:51   ` Rob Herring (Arm)
2026-09-30 12:15   ` Rob Herring
2026-09-30 22:29   ` Conor Dooley
2026-09-29 22:44 ` [PATCH v3 09/13] dt-bindings: iio: adc: adi,ad4134: Document external multiplexer usage Marcelo Schmitt
2026-09-30 12:16   ` Rob Herring (Arm)
2026-09-29 22:45 ` [PATCH v3 10/13] iio: adc: ad4134: Support SPI 4-wire mode Marcelo Schmitt
2026-09-29 23:08   ` sashiko-bot
2026-09-30 19:39     ` Marcelo Schmitt
2026-09-29 22:45 ` [PATCH v3 11/13] dt-bindings: iio: adc: adi,ad4134: Document PWM usage Marcelo Schmitt
2026-09-29 22:45 ` [PATCH v3 12/13] iio: adc: ad4134: Support high-speed data capture Marcelo Schmitt
2026-09-29 23:16   ` sashiko-bot
2026-09-30 19:59     ` Marcelo Schmitt
2026-09-30  9:42   ` Andy Shevchenko
2026-09-29 22:46 ` [PATCH v3 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=20260929230528.8861C1F000FF@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox