Devicetree
 help / color / mirror / Atom feed
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 v4 10/13] iio: adc: ad4134: Support SPI 4-wire mode
Date: Tue, 06 Oct 2026 18:35:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-162354@kernel.org> (raw)
In-Reply-To: <ec26e0e1cbb6572c8eee391951c084a7c264887c.1791309733.git.marcelo.schmitt@analog.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iio: ad4134: deadlock during probe due to recursive multiplexer locking in NO_CS mode
- [High] iio: adc: ad4134: debugfs reg access corrupts SPI mode during active capture
- [Medium] iio: ad4134: SPI mode state becomes permanently desynchronized on spi_setup() failure
--

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

iio: adc: ad4134: Support SPI 4-wire mode

AD4134 devices can be wired in a few different ways. So far, only minimum
I/O mode was supported. While minimum I/O mode allows interfacing with
AD4134 with a reduced number of wires, that wiring configuration is not
suitable for high-throughput data acquisition.

Extend AD4134 support to enable interfacing in SPI 4-wire configuration.

> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index b5207f16054e4..debc2ff027051 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c
[ ... ]
> @@ -226,6 +244,85 @@ static const struct regmap_access_table ad4134_regmap_wr_table = {
>  	.n_yes_ranges = ARRAY_SIZE(ad4134_regmap_wr_range),
>  };
>  
> +/*
> + * When operating in modes other than minimum I/O mode, AD4134 register data on
> + * the SDO line is sampled on SCLK rising edge (SPI mode 0). In addition to
> + * that, when AD4134 SDO and DOUT0 pins are multiplexed by hardware OUTSIDE
> + * AD4134 SILICON, the multiplexer state must be set to route SDO to the SPI
> + * controller. With both SPI mode and multiplexer state properly set, register
> + * access runs as usual. Successful calls to this function must be balanced with
> + * calls to ad4134_release_reg_access() so to release the mux state lock. See
> + * AD4134 IIO documentation for details.
> + */
> +static int ad4134_claim_reg_access(struct ad4134_state *st)
> +{
> +	unsigned int cur_mode = st->spi->mode & SPI_MODE_X_MASK;
> +	int ret;
> +
> +	if (st->spi_mode != AD4134_SPI_MODE_NO_CS && cur_mode != SPI_MODE_0) {
> +		st->spi->mode &= ~SPI_MODE_X_MASK;
> +		st->spi->mode |= SPI_MODE_0;
> +		ret = spi_setup(st->spi);
> +		if (ret)
> +			return ret;

[Severity: Medium]
If spi_setup() fails here, we return the error but st->spi->mode remains
modified. On subsequent calls, cur_mode != SPI_MODE_0 will evaluate to false
because the cached mode reflects the requested state.

Can this cause the driver to bypass spi_setup() on subsequent calls and
attempt to communicate with the device while the SPI hardware remains
incorrectly configured?

[Severity: High]
Can ad4134_debugfs_reg_access() execute concurrently with the active
triggered buffer capture?

ad4134_debugfs_reg_access() performs register operations without acquiring
the IIO direct mode lock. If executed concurrently with an active capture, it
will call ad4134_claim_reg_access() which modifies st->spi->mode and calls
spi_setup() without protection.

This abruptly alters the SPI hardware configuration while
ad4134_trigger_handler() is actively executing spi_sync_transfer(),
corrupting the ADC data stream and SPI transaction state.

Furthermore, if the "reg_access" and "data_read" mux states belong to
different hardware mux-controllers, the mux_state_select() call will not
block, causing concurrent, unprotected use of st->tx_buf and st->rx_buf
across threads.

> +	}
> +
> +	if (st->mux_st[AD4134_SDO_INPUT])
> +		return mux_state_select(st->mux_st[AD4134_SDO_INPUT]);
> +
> +	return 0;
> +}
[ ... ]
> @@ -594,10 +728,64 @@ static int ad4134_probe(struct spi_device *spi)
[ ... ]
> +	if (st->spi_mode == AD4134_SPI_MODE_NO_CS) {
> +		/*
> +		 * The support hardware for AD4134 may have a multiplexer for
> +		 * selecting between AD4134 SDO and AD4134 DOUT0. If that mux
> +		 * is set but the user still wants to run AD4134 in minimum I/O
> +		 * mode, then DOUT0 is not used and the multiplexer OUTSIDE OF
> +		 * AD4134 SILICON must be set to select AD4134 SDO. See AD4134
> +		 * IIO documentation for details.
> +		 */
> +		st->mux_st[AD4134_SDO_INPUT] =
> +			devm_mux_state_get_optional_selected(dev, "reg_access");

[Severity: High]
Does this cause a deadlock during device probe in NO_CS mode?

Here the driver acquires and permanently selects the SDO multiplexer via
devm_mux_state_get_optional_selected(), which acquires the multiplexer's
non-recursive semaphore.

Immediately after, probe calls ad4134_min_io_mode_setup(), which writes to
device registers via regmap_update_bits(). This triggers the following call
chain:

ad4134_min_io_mode_setup()
  regmap_update_bits()
    ad4134_reg_write()
      ad4134_claim_reg_access()

ad4134_claim_reg_access() unconditionally calls mux_state_select(), which
will attempt to acquire the exact same semaphore already held by the current
task, causing a deadlock.

Furthermore, ad4134_release_reg_access() then unconditionally calls
mux_state_deselect(), which would prematurely release the probe-acquired
lock.

> +		if (IS_ERR(st->mux_st[AD4134_SDO_INPUT]))
> +			return dev_err_probe(dev, PTR_ERR(st->mux_st[AD4134_SDO_INPUT]),
> +					     "failed to get reg_access mux-state\n");
> +
> +		ret = ad4134_min_io_mode_setup(st);
> +		if (ret)
> +			return dev_err_probe(dev, ret,
> +					     "failed to setup minimum I/O mode\n");
> +	} else {
> +		/*

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

  reply	other threads:[~2026-10-06 18:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 18:15 [PATCH v4 00/13] iio: adc: ad4134: Enable greater sample rate data capture Marcelo Schmitt
2026-10-06 18:16 ` [PATCH v4 01/13] iio: adc: ad4134: Adjust register map range Marcelo Schmitt
2026-10-06 18:16 ` [PATCH v4 02/13] iio: adc: ad4134: Sign extend sample data Marcelo Schmitt
2026-10-06 18:32   ` sashiko-bot
2026-10-06 18:16 ` [PATCH v4 03/13] iio: adc: ad4134: Update include list to comply with IWYU principles Marcelo Schmitt
2026-10-06 18:17 ` [PATCH v4 04/13] iio: adc: ad4134: Serialize single-read operations Marcelo Schmitt
2026-10-06 18:17 ` [PATCH v4 05/13] iio: adc: ad4134: Run shorter transfers when CRC is disabled Marcelo Schmitt
2026-10-06 18:32   ` sashiko-bot
2026-10-06 18:17 ` [PATCH v4 06/13] iio: adc: ad4134: Add support for digital filter type selection Marcelo Schmitt
2026-10-06 18:17 ` [PATCH v4 07/13] iio: adc: ad4134: Support buffered data read Marcelo Schmitt
2026-10-06 18:36   ` sashiko-bot
2026-10-06 18:18 ` [PATCH v4 08/13] dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode Marcelo Schmitt
2026-10-06 18:29   ` sashiko-bot
2026-10-07 10:14   ` Conor Dooley
2026-10-06 18:18 ` [PATCH v4 09/13] dt-bindings: iio: adc: adi,ad4134: Document external multiplexer usage Marcelo Schmitt
2026-10-06 18:32   ` sashiko-bot
2026-10-06 18:19 ` [PATCH v4 10/13] iio: adc: ad4134: Support SPI 4-wire mode Marcelo Schmitt
2026-10-06 18:35   ` sashiko-bot [this message]
2026-10-06 18:19 ` [PATCH v4 11/13] dt-bindings: iio: adc: adi,ad4134: Document PWM usage Marcelo Schmitt
2026-10-06 18:27   ` sashiko-bot
2026-10-06 18:19 ` [PATCH v4 12/13] iio: adc: ad4134: Support high-speed data capture Marcelo Schmitt
2026-10-06 18:35   ` sashiko-bot
2026-10-06 18:19 ` [PATCH v4 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=sashiko-outbox-162354@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