spi: spacemit: prepare both DMA descriptors before submitting

k1_spi_dma_one() currently submits the TX DMA descriptor to the DMA engine
before preparing the RX DMA descriptor. If preparing the RX descriptor
subsequently fails, the function jumps to the fallback error path without
canceling or aborting the already submitted TX DMA descriptor.

Fix this by preparing both the TX and RX descriptors before submitting
either of them to the DMA engine.

Fixes: efcd8b9d11 ("spi: spacemit: introduce SpacemiT K1 SPI controller driver")
Reviewed-by: Alex Elder <elder@riscstar.com>
Signed-off-by: Surendra Singh Chouhan <kr494167@gmail.com>
Link: https://patch.msgid.link/20260722162444.11415-1-kr494167@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Surendra Singh Chouhan
2026-07-22 22:05:55 +01:00
committed by Mark Brown
parent 6389eaf11d
commit d3c87e7153
+11 -11
View File
@@ -278,25 +278,25 @@ static int k1_spi_dma_one(struct spi_controller *host, struct spi_device *spi,
struct spi_transfer *transfer)
{
struct k1_spi_driver_data *drv_data = spi_controller_get_devdata(host);
struct dma_async_tx_descriptor *desc;
struct dma_async_tx_descriptor *txdesc, *rxdesc;
u32 val;
/* Prepare the TX descriptor and submit it */
desc = k1_spi_dma_prep(drv_data, transfer, true);
if (!desc)
/* Prepare the TX descriptor */
txdesc = k1_spi_dma_prep(drv_data, transfer, true);
if (!txdesc)
goto fallback;
dmaengine_submit(desc);
/* Prepare the RX descriptor and submit it */
desc = k1_spi_dma_prep(drv_data, transfer, false);
if (!desc)
/* Prepare the RX descriptor */
rxdesc = k1_spi_dma_prep(drv_data, transfer, false);
if (!rxdesc)
goto fallback;
/* When RX is complete we also know TX has completed */
desc->callback = k1_spi_dma_callback;
desc->callback_param = drv_data;
rxdesc->callback = k1_spi_dma_callback;
rxdesc->callback_param = drv_data;
dmaengine_submit(desc);
dmaengine_submit(txdesc);
dmaengine_submit(rxdesc);
val = readl(drv_data->base + SSP_TOP_CTRL);
val |= TOP_TRAIL; /* Trailing bytes handled by DMA */