From: sashiko-bot@kernel.org
To: "Javier Fernandez Pastrana" <javier.pastrana@linutronix.de>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2] spi: imx: reconfigure for PIO when DMA cannot be started
Date: Wed, 24 Jun 2026 15:31:57 +0000 [thread overview]
Message-ID: <20260624153157.B0B771F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260624151958.18626-1-javier.pastrana@linutronix.de>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing SPI_TRANS_FAIL_NO_START flag when TX DMA preparation or submission fails, preventing PIO fallback.
- [High] Mid-transfer DMA failure incorrectly triggers a full PIO fallback, causing duplicate data transmission and corrupting the SPI stream.
- [High] Failure to clear `SPI_TRANS_FAIL_NO_START` after an internal PIO fallback leaks stale error state, causing subsequent transfers to silently duplicate data.
--
commit 5c8ab49e90372d3c0d5a4aca24ae8e97fcecafbc
Author: Javier Fernandez Pastrana <javier.pastrana@linutronix.de>
spi: imx: reconfigure for PIO when DMA cannot be started
When ECSPI DMA descriptor preparation fails, the driver falls back to PIO
internally without un-doing the DMA-mode controller configuration, leading
to corrupted data. This commit forces the controller to reconfigure for
PIO by setting the fallback flag and re-running the setup transfer
routine.
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index ae9912905c67a..79a6c1a60b0a0 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -2152,7 +2152,8 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
> if (spi_imx->usedma) {
> ret = spi_imx_dma_transfer(spi_imx, transfer);
> if (transfer->error & SPI_TRANS_FAIL_NO_START) {
[Severity: High]
This isn't a bug introduced by this patch, but if a transfer succeeds
internally via the PIO fallback here, doesn't transfer->error still retain
the SPI_TRANS_FAIL_NO_START flag?
If an SPI client reuses the spi_transfer object, and the next transfer
finishes successfully via DMA, this condition checks only the error flag
without verifying if the DMA transfer actually failed (ret < 0).
Would this cause the successful DMA transfer to incorrectly evaluate this
condition as true and redundantly re-transmit the data via PIO?
> - spi_imx->usedma = false;
> + controller->fallback = true;
> + spi_imx_setupxfer(spi, transfer);
> if (spi_imx->target_mode)
> return spi_imx_pio_transfer_target(spi, transfer);
> else
> return spi_imx_pio_transfer(spi, transfer);
> }
[Severity: High]
This is also a pre-existing issue, but does this fallback logic account for
partially completed DMA transmissions?
If a large transfer is split into multiple DMA packages in
spi_imx_dma_transfer() and a subsequent package fails,
spi_imx_dma_package_transfer() unconditionally sets SPI_TRANS_FAIL_NO_START:
spi_imx_dma_package_transfer() {
...
dma_failure_no_start:
transfer->error |= SPI_TRANS_FAIL_NO_START;
return ret;
}
Since earlier packages were already physically transmitted over the SPI bus,
would triggering a full PIO fallback here restart the transfer from the
beginning and corrupt the SPI stream by transmitting duplicate data?
[Severity: High]
Another pre-existing issue related to the DMA fallback: what happens if TX
DMA descriptor preparation or submission fails in spi_imx_dma_submit()?
drivers/spi/spi-imx.c:spi_imx_dma_submit() {
...
desc_tx = dmaengine_prep_slave_single(controller->dma_tx, ...);
if (!desc_tx)
goto dmaengine_terminate_rx;
...
cookie = dmaengine_submit(desc_tx);
if (dma_submit_error(cookie)) {
...
goto dmaengine_terminate_tx;
}
...
}
It appears these error paths return without setting the
SPI_TRANS_FAIL_NO_START flag. Does this prevent the PIO fallback from
triggering for TX DMA failures, causing the transfer to drop instead?
> return ret;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260624151958.18626-1-javier.pastrana@linutronix.de?part=1
next prev parent reply other threads:[~2026-06-24 15:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 15:19 [PATCH v2] spi: imx: reconfigure for PIO when DMA cannot be started Javier Fernandez Pastrana
2026-06-24 15:27 ` Carlos Song
2026-06-24 15:31 ` sashiko-bot [this message]
2026-06-24 16:30 ` Frank Li
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=20260624153157.B0B771F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=javier.pastrana@linutronix.de \
--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