[PATCH] spi: imx: Avoid PIO replay after a completed DMA package
From: Baek Kyu, Kim
Date: Sat Oct 31 2026 - 02:04:00 EST
A transfer can span two DMA packages. If the first package completes but
preparing the second one fails, the helper sets SPI_TRANS_FAIL_NO_START
for the second package. The driver treats that flag as applying to the
whole transfer and retries all of it through PIO, sending the completed
prefix twice and reporting success.
Clear NO_START after a failed later package has been unmapped. The driver
then returns the original error without replaying the transfer. A failure
in the first package still takes the existing PIO fallback path.
Fixes: faa8e404ad8e ("spi: imx: support dynamic burst length for ECSPI DMA mode")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@xxxxxxxxx>
---
In an arm64 QEMU/KVM kernel, the SPI core and spi-imx driver ran with
modeled MMIO/FIFO and DMA provider callbacks. A 513-byte transfer
completed its first 512-byte package; failing RX descriptor preparation
for the second package made the original driver replay all 513 bytes
through PIO and report success (1025 bytes in the modeled record). With
this change it returned -EINVAL after the first 512 bytes and sent no
PIO bytes. First-package fallback still completed through PIO. No
physical ECSPI/SDMA device or external slave was tested.
drivers/spi/spi-imx.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 79a6c1a60b0a0..eed1936388aa8 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1968,6 +1968,9 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
spi_imx_dma_unmap(spi_imx, &spi_imx->dma_data[i]);
if (ret < 0) {
+ /* Earlier packages have already been transferred. */
+ if (i)
+ transfer->error &= ~SPI_TRANS_FAIL_NO_START;
dev_dbg(spi_imx->dev, "DMA %d transfer not really finish\n", i);
break;
}
--
2.55.0