Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kurt Borja" <kuurtb@gmail.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 08/10] iio: adc: ti-ads1262: support triggered buffer sampling
Date: Fri, 28 Aug 2026 06:57:16 +0000	[thread overview]
Message-ID: <20260828065717.350741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828-ads126x-v4-8-1dc27e9c0260@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The `rx` buffer in `struct ads1262` lacks the `__aligned(IIO_DMA_MINALIGN)` attribute, causing it to be placed at an unaligned memory offset and sharing a cacheline with the `tx` buffer.
- [High] The driver fails to filter out the IIO soft timestamp channel when iterating over `active_scan_mask`, treating it as a hardware channel. This leads to out-of-bounds array reads and writes, including a potential `FORTIFY_SOURCE` kernel panic.
- [High] The driver dynamically modifies a pre-optimized SPI transfer buffer without cache synchronization, breaking DMA coherency on architectures without hardware cache coherency.
--

commit 21b4fc84b4dd63fd1e3310ee7b41df30e8039785
Author: Kurt Borja <kuurtb@gmail.com>
Subject: iio: adc: ti-ads1262: support triggered buffer sampling

Add triggered buffer support and a data-ready (DRDY) hardware trigger.

> diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c
> index 04566d00d7cb8..3f6d34a08b296 100644
> --- a/drivers/iio/adc/ti-ads1262.c
> +++ b/drivers/iio/adc/ti-ads1262.c
[ ... ]
> @@ -232,6 +239,11 @@ struct ads1262 {
>  	u32 rref_ohms[ADS1262_EXT_REF_COUNT][ADS1262_EXT_REF_COUNT];
>  	int refp_uV[ADS1262_EXT_REF_COUNT];
>  	int refn_uV[ADS1262_EXT_REF_COUNT];
> +	IIO_DECLARE_BUFFER_WITH_TS(__be32, scan_buffer,
> +				   ADS1262_FW_CHANNEL_COUNT +
> +				   ADS1262_MON_CHANNEL_COUNT);
> +	u8 tx[ADS1262_SPI_XFER_SZ] __aligned(IIO_DMA_MINALIGN);
> +	u8 rx[ADS1262_SPI_XFER_SZ];

[Severity: High]
Does the rx buffer need the __aligned(IIO_DMA_MINALIGN) attribute as well?

Without it, rx might be placed at an unaligned memory offset and share a
cacheline with the tx buffer. Since they are mapped for DMA in opposite
directions (DMA_TO_DEVICE and DMA_FROM_DEVICE), mapping overlapping
cachelines can violate the DMA API and cause memory corruption on
non-cache-coherent architectures.

>  };
>  
>  static const char * const ads1262_device_id_to_name[] = {
[ ... ]
> @@ -837,10 +849,284 @@ static const struct iio_info ads1262_iio_info = {
[ ... ]
> +static int ads1262_fill_buffer_mult(struct iio_dev *indio_dev)
> +{
> +	struct ads1262 *st = iio_priv(indio_dev);
> +	unsigned int chan;
> +	int i = -1;
> +	int ret;
> +
> +	/*
> +	 * This routine enables and reads channels in a full-duplex fashion.
> +	 *
> +	 * When a channel is enabled, the previous conversion is clocked out of
> +	 * the shift data register on the same transfer (Section 9.4.7.1). This
> +	 * allows for low latency software sequencing but forbids any
> +	 * communication with the chip in-between or data corruption may occur,
> +	 * hence the need to take the xfer_lock for the whole operation.
> +	 */
> +	guard(mutex)(&st->xfer_lock);
> +
> +	iio_for_each_active_channel(indio_dev, chan) {
> +		ads1262_channel_prep_tx(st, &indio_dev->channels[chan]);

[Severity: High]
Is it possible for this loop to iterate over the IIO soft timestamp channel?

If the timestamp channel is enabled and its bit is set in active_scan_mask,
iio_for_each_active_channel() will yield the timestamp channel's index.

This would cause ads1262_channel_prep_tx() to perform an out-of-bounds read
on the st->channels array since the timestamp channel is treated as a
hardware channel:

	struct ads1262_channel *chan = &st->channels[spec->scan_index];

Additionally, the extra loop iteration could cause the following memcpy to
write past the bounds of the scan_buffer array when all channels are active:

	memcpy(&st->scan_buffer[i], st->rx, sizeof(st->scan_buffer[i]));

> +
> +		reinit_completion(&st->drdy);
> +
> +		ret = spi_sync(st->spi, &st->msg);

[Severity: High]
Could this sequence break DMA coherency on architectures without hardware
cache coherency?

If the SPI message is permanently mapped for DMA in
ads1262_buffer_postenable_mult() via spi_optimize_message():

	return spi_optimize_message(st->spi, &st->msg);

And then on every trigger event, ads1262_channel_prep_tx() dynamically writes
new register commands directly into the st->tx buffer from the CPU:

	st->tx[0] = ADS1262_MODE0_REG | ADS1262_OPCODE_WREG;

When ads1262_fill_buffer_mult() later calls spi_sync(), the message is
already marked as pre-optimized, so dma_sync_single_for_device() might
be skipped. Will the SPI controller fetch stale cached data instead of
the newly written configuration commands?

> +		if (ret)
> +			return ret;
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828-ads126x-v4-0-1dc27e9c0260@gmail.com?part=8

  reply	other threads:[~2026-08-28  6:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28  6:38 [PATCH v4 00/10] iio: adc: Add TI ADS126X ADC family support Kurt Borja
2026-08-28  6:38 ` [PATCH v4 01/10] dt-bindings: adc: add excitation-current-chopping property Kurt Borja
2026-08-28 16:33   ` Conor Dooley
2026-08-28  6:38 ` [PATCH v4 02/10] dt-bindings: iio: adc: support the TI ADS126x ADC family Kurt Borja
2026-08-28  6:45   ` sashiko-bot
2026-08-28 16:39   ` Conor Dooley
2026-08-28  6:38 ` [PATCH v4 03/10] iio: adc: add the ti-ads1262 driver Kurt Borja
2026-08-28  6:52   ` sashiko-bot
2026-08-28  8:09   ` Andy Shevchenko
2026-08-28  6:38 ` [PATCH v4 04/10] iio: adc: ti-ads1262: support per-channel sampling frequency Kurt Borja
2026-08-28  7:03   ` sashiko-bot
2026-08-28  6:38 ` [PATCH v4 05/10] iio: adc: ti-ads1262: support per-channel reference and gain Kurt Borja
2026-08-28  6:38 ` [PATCH v4 06/10] iio: adc: ti-ads1262: support input chopping Kurt Borja
2026-08-28  6:38 ` [PATCH v4 07/10] iio: adc: ti-ads1262: support excitation currents Kurt Borja
2026-08-28  6:57   ` sashiko-bot
2026-08-28  6:38 ` [PATCH v4 08/10] iio: adc: ti-ads1262: support triggered buffer sampling Kurt Borja
2026-08-28  6:57   ` sashiko-bot [this message]
2026-08-28  6:38 ` [PATCH v4 09/10] iio: adc: ti-ads1262: support REFOUT and VBIAS regulators Kurt Borja
2026-08-28  6:53   ` sashiko-bot
2026-08-28  6:38 ` [PATCH v4 10/10] iio: adc: ti-ads1262: support common mode supplies Kurt Borja
2026-08-28  7:03   ` sashiko-bot

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=20260828065717.350741F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kuurtb@gmail.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