]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: fsl-lpspi: terminate the RX channel on TX prepare failure path
authorCarlos Song <carlos.song@nxp.com>
Mon, 25 May 2026 06:23:57 +0000 (14:23 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 1 Jun 2026 14:08:06 +0000 (15:08 +0100)
When dmaengine_prep_slave_sg() fails for the TX channel, the error path
terminates the TX DMA channel but leaves the RX channel running. Since
the RX channel was already submitted and issued prior to preparing
the TX descriptor, returning -EINVAL causes the SPI core to unmap the
DMA buffers while the RX DMA engine continues writing to them, leading
to potential memory corruption or use-after-free.

Terminate the RX channel before returning on the TX prepare failure path.

Fixes: 09c04466ce7e ("spi: lpspi: add dma mode support")
Cc: stable@vger.kernel.org
Signed-off-by: Carlos Song <carlos.song@nxp.com>
Link: https://patch.msgid.link/20260525062357.3191349-3-carlos.song@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-fsl-lpspi.c

index 1a94a42fac319d8b37c30bcb646607c831603156..e14753144e19d6b43215de43a06b620c5df3d5c3 100644 (file)
@@ -647,7 +647,7 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller,
                                tx->sgl, tx->nents, DMA_MEM_TO_DEV,
                                DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
        if (!desc_tx) {
-               dmaengine_terminate_sync(controller->dma_tx);
+               dmaengine_terminate_sync(controller->dma_rx);
                return -EINVAL;
        }