Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt1@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v1 3/4] iio: adc: ltc2378: Enable high-speed data capture
Date: Mon, 18 May 2026 16:19:25 +0000	[thread overview]
Message-ID: <20260518161926.59284C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <580ce8e03cdbda8ec20fed2e26f2226872ffcef3.1779117444.git.marcelo.schmitt1@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Missing early return in `ltc2378_offload_buffer_setup()` causes error pointer dereference and breaks fallback mode.
- [High] Unconditional exposure of sysfs attributes causes a NULL pointer dereference on devices without SPI offload.
- [High] Unbounded `do...while` loops querying hardware limits can cause an infinite loop and system hang.
- [High] Hardcoded 4-byte SPI offload transfers conflict with 16-bit IIO buffer allocations, causing data corruption.
- [Medium] Kconfig dependency mismatch prevents enabling the offload feature when the driver is compiled as a module.
--

commit 87ed4789078a187c9262ff17873220fb5108858f
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>

iio: adc: ltc2378: Enable high-speed data capture

Makes use of SPI transfer offloading to speed up data capture, enabling data
acquisition at faster sample rates (up to 2 MSPS).

> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 70fec8e3e891f..b5368ee783f7b 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
[ ... ]
> +config LTC2378_OFFLOAD_BUFFER
> +	bool "Offloaded data capture with LTC2378"
> +	depends on SPI && LTC2378

LTC2378_OFFLOAD_BUFFER is a bool that depends on LTC2378. Since LTC2378 is a
tristate, if a user compiles the driver as a module, won't Kconfig restrict
this dependent boolean to n? Does this prevent enabling the offload feature
entirely unless the driver is built-in?

> diff --git a/drivers/iio/adc/ltc2378-offload-buffer.c b/drivers/iio/adc/ltc2378-offload-buffer.c
> new file mode 100644
> index 0000000000000..ed09f9a55f93e
> --- /dev/null
> +++ b/drivers/iio/adc/ltc2378-offload-buffer.c
[ ... ]
> +static int ltc2378_update_conversion_rate(struct ltc2378_state *st, int freq_Hz)
> +{
[ ... ]
> +	do {
> +		cnv_wf.duty_length_ns = target;
> +		ret = pwm_round_waveform_might_sleep(st->cnv_trigger, &cnv_wf);
> +		if (ret)
> +			return ret;
> +		target += 10;  /* Increment by PWM duty cycle period */
> +	} while (cnv_wf.duty_length_ns < LTC2378_TCNV_HIGH_NS);

If the physical PWM hardware clamps the duty cycle below LTC2378_TCNV_HIGH_NS
due to hardware limits or resolution, will this loop increment target
indefinitely and stall the CPU? Should there be a maximum iteration limit?

This same concern applies to the SPI trigger offset negotiation loop located
just below this one.

[ ... ]
> +static int ltc2378_prepare_offload_message(struct device *dev,
> +					   struct ltc2378_state *st)
> +{
> +	st->offload_xfer.bits_per_word = st->info->resolution;
> +	/*
> +	 * Ideally, we would ask the offload provider what data word sizes are
> +	 * supported so we could use smaller words for less precise ADCs.
> +	 * Though, the currently available SPI offloading hardware only supports
> +	 * pushing 32-bit sized data elements to DMA memory. Because of that,
> +	 * we hardcode set 4 byte sized transfers.
> +	 */
> +	st->offload_xfer.len = 4;

Since st->offload_xfer.len is hardcoded to 4 bytes here, but
ltc2378_chan->scan_type.storagebits remains at 16 for ADCs with 16-bit
or lower resolution, does this cause a mismatch? Will the IIO core allocate
DMA buffers assuming 2 bytes per sample while the DMA hardware pushes
4 bytes, potentially leading to buffer overruns and data corruption?

[ ... ]
> +int ltc2378_offload_buffer_setup(struct iio_dev *indio_dev, struct spi_device *spi)
> +{
> +	struct ltc2378_state *st = iio_priv(indio_dev);
> +	struct device *dev = &spi->dev;
> +	int ret;
> +
> +	st->offload = devm_spi_offload_get(dev, spi, &ltc2378_offload_config);
> +	ret = PTR_ERR_OR_ZERO(st->offload);
> +	if (ret && ret != -ENODEV)
> +		return dev_err_probe(dev, ret, "failed to get offload\n");
> +
> +	ret = ltc2378_spi_offload_setup(indio_dev, st);

If devm_spi_offload_get() returns -ENODEV, this check bypasses the
dev_err_probe() call but continues to ltc2378_spi_offload_setup() without
returning. 

Could this pass an ERR_PTR(-ENODEV) via st->offload to
devm_spi_offload_trigger_get(), causing a panic or breaking ltc2378_probe()'s
intended fallback to non-offloaded direct mode?

> diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
> index 7916500c470cf..fdbe919d45d55 100644
> --- a/drivers/iio/adc/ltc2378.c
> +++ b/drivers/iio/adc/ltc2378.c
[ ... ]
> @@ -226,6 +266,9 @@ static int ltc2378_read_raw(struct iio_dev *indio_dev,
>  }
>  
>  static const struct iio_info ltc2378_iio_info = {
> +#ifdef CONFIG_LTC2378_OFFLOAD_BUFFER
> +	.attrs = &ltc2378_offload_attribute_group,
> +#endif
>  	.read_raw = &ltc2378_read_raw,
>  };

If a device probes successfully without SPI offload using standard direct mode,
st->cnv_trigger remains uninitialized. Since these attributes are statically
assigned without an is_visible callback, they remain exposed to userspace.

Could writing to sampling_frequency in sysfs trigger a NULL pointer
dereference when ltc2378_update_conversion_rate() passes the uninitialized
st->cnv_trigger to pwm_round_waveform_might_sleep()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1779117444.git.marcelo.schmitt1@gmail.com?part=3

  reply	other threads:[~2026-05-18 16:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18 15:20 [PATCH v1 0/4] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
2026-05-18 15:21 ` [PATCH v1 1/4] dt-bindings: iio: adc: Add ltc2378 Marcelo Schmitt
2026-05-18 15:29   ` sashiko-bot
2026-05-18 17:06   ` Conor Dooley
2026-05-18 18:42     ` Marcelo Schmitt
2026-05-18 15:21 ` [PATCH v1 2/4] iio: adc: Add support for LTC2378-20 and similar ADCs Marcelo Schmitt
2026-05-18 15:51   ` sashiko-bot
2026-05-18 15:22 ` [PATCH v1 3/4] iio: adc: ltc2378: Enable high-speed data capture Marcelo Schmitt
2026-05-18 16:19   ` sashiko-bot [this message]
2026-05-18 15:22 ` [PATCH v1 4/4] iio: adc: ltc2378: Enable triggered buffer " 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=20260518161926.59284C2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=marcelo.schmitt1@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