Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v1 05/13] iio: adc: ad4134: Run shorter transfers when CRC is disabled
Date: Wed, 02 Sep 2026 17:42:25 +0000	[thread overview]
Message-ID: <20260902174225.BCAAF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <e7f106f7cfae15675a3c04a57d486b478b182705.1788368334.git.marcelo.schmitt@analog.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The TX and RX SPI buffers (`tx_buf` and `rx_buf`) share the same cacheline, violating the DMA API constraints for concurrent bidirectional mapping and causing potential memory corruption.
- [Medium] Incorrect SPI CRC verification logic compares the received response CRC against the transmitted command CRC, causing spurious validation failures and rendering the CRC check useless.
--

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

iio: adc: ad4134: Run shorter transfers when CRC is disabled

When AD4134 has its SPI CRC feature enabled, one extra byte (the CRC code)
is sent through SPI for both ends to verify the integrity of data
transfers. Though, when CRC is not enabled, SPI transfers can be shorter.

> diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> index 3460ecf4cafd4..7da6734d4609f 100644
> --- a/drivers/iio/adc/ad4134.c
> +++ b/drivers/iio/adc/ad4134.c
> @@ -102,6 +102,7 @@ struct ad4134_state {
>  	unsigned long sys_clk_hz;
>  	struct gpio_desc *odr_gpio;
>  	int refin_mv;
> +	bool crc_en;

[Severity: High]
This is a pre-existing issue, but does struct ad4134_state force tx_buf
and rx_buf to share a cacheline?

Looking at the struct definition, rx_buf is annotated with
__aligned(IIO_DMA_MINALIGN), which aligns its start address:

	u8 rx_buf[AD4134_SPI_MAX_XFER_LEN] __aligned(IIO_DMA_MINALIGN);
	u8 tx_buf[AD4134_SPI_MAX_XFER_LEN];

Because rx_buf is only 3 bytes long and tx_buf immediately follows it
without its own alignment, tx_buf resides in the exact same cacheline.

When both buffers are passed simultaneously to spi_sync_transfer() during
ad4134_reg_write() or ad4134_register_read(), they are mapped concurrently.

Will performing a simultaneous flush for tx_buf and invalidate for rx_buf
on the same cacheline violate DMA API rules and cause memory corruption
on non-coherent architectures?

>  	/*
>  	 * Synchronize access to members the of driver state, and ensure
>  	 * atomicity of consecutive register access operations.

[ ... ]

> @@ -170,7 +171,7 @@ static int ad4134_reg_write(void *context, unsigned int reg, unsigned int val)
>  	if (ret)
>  		return ret;
>  
> -	if (st->rx_buf[2] != st->tx_buf[2])
> +	if (st->crc_en && st->rx_buf[2] != st->tx_buf[2])

[Severity: Medium]
This isn't a bug introduced by this patch, but is the CRC validation logic
comparing the correct values?

In ad4134_reg_write(), the outgoing command CRC is calculated over the
instruction and stored in st->tx_buf[2]. The incoming response CRC computed
by the device is placed in st->rx_buf[2].

Because the transmitted data differs from the received data, won't comparing
the response CRC directly against the command CRC result in constant
mismatch failures?

>  		dev_dbg(&st->spi->dev, "reg write CRC check failed\n");
>  
>  	return 0;

[ ... ]

> @@ -231,7 +232,7 @@ static int ad4134_register_read(struct ad4134_state *st, unsigned int reg,
>  	*val = st->rx_buf[1];
>  
>  	/* Check CRC */
> -	if (st->rx_buf[2] != st->tx_buf[2])
> +	if (st->crc_en && st->rx_buf[2] != st->tx_buf[2])

[Severity: Medium]
This is a pre-existing issue, but does this comparison render the CRC check
useless for register reads?

Similar to the write path above, st->tx_buf[2] holds the CRC for the
outgoing command (including a dummy data byte), while st->rx_buf[2] holds
the device's CRC over the read response (which includes the actual register
value).

Since the response data is mathematically unrelated to the outgoing command,
will this always produce false-positive CRC check failures rather than
actually validating incoming data integrity?

>  		dev_dbg(&st->spi->dev, "reg read CRC check failed\n");
>  
>  	return 0;

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

  reply	other threads:[~2026-09-02 17:42 UTC|newest]

Thread overview: 32+ 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-04 19:41     ` Marcelo Schmitt
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 [this message]
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-04 20:47     ` Marcelo Schmitt
2026-09-04 22:06       ` Marcelo Schmitt
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-04 15:53   ` Conor Dooley
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
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=20260902174225.BCAAF1F000E9@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