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 v1 12/13] iio: adc: ad4134: Support high-speed data capture
Date: Wed, 02 Sep 2026 17:49:43 +0000 [thread overview]
Message-ID: <20260902174944.286BC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <53d79eed25795db5076d7c591f6dd8cf4feedfec.1788368334.git.marcelo.schmitt@analog.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] Buffer overflow in `ad4134_trigger_handler` when iterating over the scan mask length.
- [High] NULL pointer dereference in `ad4134_offload_buffer_postenable` error path for AD4134_SPI_MODE_NO_CS.
- [High] Incorrect SPI transfer length in 1-lane offload mode causes buffer format mismatch and data corruption.
- [High] Hardware PWM resource leak on driver unbind due to missing disable action.
- [Medium] Data race on `st->odr_hz` in `ad4134_read_raw` due to missing lock.
--
commit d7cbe54fc38bde7020274d75b09e6803ffb16fca
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>
iio: adc: ad4134: Support high-speed data capture
This commit adds support for SPI transfer offloading to speed up data
capture, enabling data acquisition at faster sample rates up to 1.496 MSPS.
> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index 8453b44ef368f..cf84d2b24417d 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c
[ ... ]
> @@ -454,6 +509,90 @@ static const struct regmap_config ad4134_regmap_config = {
> .max_register = AD4134_CH_VREG(ARRAY_SIZE(ad4134_chan_set)),
> };
>
> +static int ad4134_update_conversion_rate(struct ad4134_state *st,
> + unsigned int freq_Hz)
> +{
[ ... ]
> + ret = pwm_set_waveform_might_sleep(st->odr_pwm, &odr_wf, false);
[Severity: High]
This starts the ODR PWM hardware, but is there a corresponding cleanup
action or devm callback registered to stop it on driver unbind? Does this
leave the hardware toggling indefinitely if the driver is unbound or if an
error occurs during probe?
> + if (ret)
> + return ret;
> +
> + st->offload_trigger_config = config;
> + st->odr_wf = odr_wf;
> + st->odr_hz = DIV_ROUND_UP_ULL(NSEC_PER_SEC, odr_wf.period_length_ns);
> +
> + return 0;
> +}
[ ... ]
> @@ -537,6 +676,42 @@ static int ad4134_read_raw(struct iio_dev *indio_dev,
> *val2 = AD4134_CHAN_PRECISION_BITS - 1;
>
> return IIO_VAL_FRACTIONAL_LOG2;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = st->odr_hz;
> + return IIO_VAL_INT;
[Severity: Medium]
Is it safe to read st->odr_hz locklessly here? Concurrent writes via
ad4134_write_raw() hold st->lock while modifying this value, which could
lead to a data race if userspace concurrently reads and writes the
sampling frequency sysfs attribute.
> + default:
> + return -EINVAL;
> + }
> +}
[ ... ]
> @@ -588,6 +763,176 @@ static const struct iio_info ad4134_info = {
> .debugfs_reg_access = ad4134_debugfs_reg_access,
> };
>
> +static const struct iio_info ad4134_offload_info = {
[ ... ]
> +static void ad4134_prepare_offload_msg(struct iio_dev *indio_dev)
> +{
> + struct ad4134_state *st = iio_priv(indio_dev);
> + unsigned int base_len = roundup_pow_of_two(BITS_TO_BYTES(AD4134_CHAN_PRECISION_BITS));
> + unsigned int bpw = AD4134_CHAN_PRECISION_BITS;
> +
> + st->xfers.cs_off = 1;
> + st->xfers.bits_per_word = bpw;
> + st->xfers.len = base_len * st->spi->num_rx_lanes;
[Severity: High]
Since ad4134_scan_masks statically requires all 4 channels to be present
via GENMASK(3, 0), meaning 16 bytes per trigger are required, will this
length calculation of just 4 bytes in 1-lane mode cause the DMA to push
incomplete frames and corrupt the IIO buffer?
> + if (st->spi->num_rx_lanes > 1)
> + st->xfers.multi_lane_mode = SPI_MULTI_LANE_MODE_STRIPE;
> +
> + st->xfers.offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
> +
> + spi_message_init_with_transfers(&st->msg, &st->xfers, 1);
> +}
> +
> +static int ad4134_offload_buffer_postenable(struct iio_dev *indio_dev)
> +{
[ ... ]
> + ret = spi_offload_trigger_enable(st->offload, st->offload_trigger,
> + &st->offload_trigger_config);
> + if (ret)
> + goto out_unoptimize;
> +
> + return 0;
> +
> +out_unoptimize:
> + spi_unoptimize_message(&st->msg);
> +
> +out_set_register_input:
> + ret2 = ad4134_set_register_access(st);
[Severity: High]
If the SPI mode is AD4134_SPI_MODE_NO_CS, the mux control pointer
st->mux_st[AD4134_DOUT0_INPUT] is never initialized. When jumping to
out_set_register_input on an error path, will ad4134_set_register_access()
blindly dereference the NULL mux state when calling
mux_state_deselect(st->mux_st[AD4134_DOUT0_INPUT]), crashing the kernel?
> + if (ret2)
> + dev_err(&st->spi->dev, "reg input select error: %d\n", ret2);
> +
> + return ret;
> +}
[ ... ]
> @@ -747,12 +1089,30 @@ static int ad4134_probe(struct spi_device *spi)
> indio_dev->setup_ops = &ad4134_buffer_setup_ops;
> }
>
> - ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> - iio_pollfunc_store_time,
> - ad4134_trigger_handler,
> - NULL);
> - if (ret)
> - return ret;
> + st->offload = devm_spi_offload_get(dev, spi, &ad4134_offload_config);
> + ret = PTR_ERR_OR_ZERO(st->offload);
> + /* Fall back to low speed usage when no SPI offload is available. */
> + if (ret == -ENODEV) {
> + indio_dev->info = &ad4134_info;
> + indio_dev->channels = ad4134_chan_set;
> + indio_dev->num_channels = ARRAY_SIZE(ad4134_chan_set);
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> + iio_pollfunc_store_time,
> + ad4134_trigger_handler,
> + NULL);
[Severity: Critical]
When falling back to low speed usage, ad4134_chan_set configures 5 channels
total (4 data channels plus IIO_CHAN_SOFT_TIMESTAMP). Inside
ad4134_trigger_handler(), the code loops up to iio_get_masklength() which
will be 5:
for (unsigned int ch = 0; ch < iio_get_masklength(indio_dev); ch++) {
ret = spi_write_then_read(st->spi, NULL, 0, &st->scan[ch], ...);
But st->scan is only sized for AD4134_NUM_CHANNELS (4 elements). Does this
cause an out-of-bounds write for the 5th channel, corrupting memory?
> + if (ret)
> + return ret;
> + } else if (ret) {
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788368334.git.marcelo.schmitt@analog.com?part=12
next prev parent reply other threads:[~2026-09-02 17:49 UTC|newest]
Thread overview: 28+ 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-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-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
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-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-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 [this message]
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=20260902174944.286BC1F000E9@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