From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Date: Thu, 09 Jul 2026 21:04:41 +0000 [thread overview]
Message-ID: <20260709210441.C953C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <965e5a31bf10cb49b53f7351266eeed55e8f6bd5.1783629101.git.marcelo.schmitt@analog.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The internal mutex `st->lock` is released before reading the shared SPI transfer buffer, failing to protect the single-sample read procedure.
--
--- Patch [2]: [PATCH v6 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs ---
commit 30c9caf90bdc7e619336a9deac3d3aa86c429417
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>
iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Support for LTC2378-20 and similar analog-to-digital converters.
> diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/iio/adc/ltc2378.c
[ ... ]
> +static int ltc2378_convert_and_acquire(struct ltc2378_state *st)
> +{
> + int ret;
> +
> + guard(mutex)(&st->lock);
[Severity: Medium]
Does the use of guard(mutex) here release the lock before the data is safely
extracted?
The lock is automatically released when this function returns, which means
st->lock drops before ltc2378_channel_single_read() can consume the shared
st->scan.data buffer.
> + /* Cause a rising edge of CNV to initiate a new ADC conversion */
> + gpiod_set_value_cansleep(st->cnv_gpio, 1);
> + fsleep(4);
> + ret = spi_sync_transfer(st->spi, &st->xfer, 1);
> + gpiod_set_value_cansleep(st->cnv_gpio, 0);
> +
> + return ret;
> +}
> +
> +static int ltc2378_channel_single_read(const struct iio_chan_spec *chan,
> + struct ltc2378_state *st, int *val)
> +{
> + const struct iio_scan_type *scan_type = &chan->scan_type;
> + u32 sample;
> + int ret;
> +
> + ret = ltc2378_convert_and_acquire(st);
> + if (ret)
> + return ret;
> +
> + if (chan->scan_type.endianness == IIO_BE) {
> + if (chan->scan_type.realbits > 16)
> + sample = be32_to_cpu(st->scan.data.sample_buf32_be);
[Severity: Medium]
Is this read of st->scan.data properly protected against concurrent access?
Since ltc2378_convert_and_acquire() uses guard(mutex) to manage the lock,
the lock is dropped before returning. This leaves the access to
st->scan.data here unprotected by st->lock.
While the IIO core's direct mode mlock currently serializes these calls,
this early release seems to break the intent stated in the commit message
where the single sample read procedure is protected with a mutex.
> + else
> + sample = be16_to_cpu(st->scan.data.sample_buf16_be);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1783629101.git.marcelo.schmitt@analog.com?part=2
next prev parent reply other threads:[~2026-07-09 21:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 20:49 [PATCH v6 0/4] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
2026-07-09 20:49 ` [PATCH v6 1/4] dt-bindings: iio: adc: Add ltc2378 Marcelo Schmitt
2026-07-09 20:58 ` sashiko-bot
2026-07-10 21:06 ` Marcelo Schmitt
2026-07-09 20:49 ` [PATCH v6 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs Marcelo Schmitt
2026-07-09 21:04 ` sashiko-bot [this message]
2026-07-10 2:22 ` Jonathan Cameron
2026-07-11 15:45 ` David Lechner
2026-07-09 20:50 ` [PATCH v6 3/4] iio: adc: ltc2378: Enable high-speed data capture Marcelo Schmitt
2026-07-09 23:24 ` sashiko-bot
2026-07-10 21:15 ` Marcelo Schmitt
2026-07-11 15:44 ` David Lechner
2026-07-09 20:50 ` [PATCH v6 4/4] iio: adc: ltc2378: Enable triggered buffer " Marcelo Schmitt
2026-07-11 15:49 ` [PATCH v6 0/4] iio: adc: Add support for LTC2378 and similar ADCs David Lechner
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=20260709210441.C953C1F000E9@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