* [PATCH v2 0/2] spi: fsl-lpspi: fix DMA termination issues
@ 2026-05-20 9:43 Carlos Song (OSS)
2026-05-20 9:43 ` [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync Carlos Song (OSS)
2026-05-20 9:43 ` [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure Carlos Song (OSS)
0 siblings, 2 replies; 5+ messages in thread
From: Carlos Song (OSS) @ 2026-05-20 9:43 UTC (permalink / raw)
To: Frank.Li, broonie, xiaoning.wang, Fugang.duan
Cc: linux-spi, imx, linux-kernel, Carlos Song
From: Carlos Song <carlos.song@nxp.com>
This series fixes two issues in the fsl-lpspi DMA transfer error paths.
Patch 1 replaces the deprecated dmaengine_terminate_all() with
dmaengine_terminate_sync() across all error paths in
fsl_lpspi_dma_transfer().
Patch 2 fixes a missing RX DMA channel termination when TX descriptor
preparation fails. Since the RX channel is already submitted and issued
before the TX descriptor is prepared, returning -EINVAL without
terminating the RX channel leaves it running against buffers that the
SPI core will unmap, potentially causing memory corruption.
Carlos Song (2):
spi: fsl-lpspi: replace dmaengine_terminate_all with
dmaengine_terminate_sync
spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure
drivers/spi/spi-fsl-lpspi.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync 2026-05-20 9:43 [PATCH v2 0/2] spi: fsl-lpspi: fix DMA termination issues Carlos Song (OSS) @ 2026-05-20 9:43 ` Carlos Song (OSS) 2026-05-20 16:52 ` Frank Li 2026-05-20 9:43 ` [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure Carlos Song (OSS) 1 sibling, 1 reply; 5+ messages in thread From: Carlos Song (OSS) @ 2026-05-20 9:43 UTC (permalink / raw) To: Frank.Li, broonie, xiaoning.wang, Fugang.duan Cc: linux-spi, imx, linux-kernel, Carlos Song, stable From: Carlos Song <carlos.song@nxp.com> The terminate API dmaengine_terminate_all() has been deprecated, improve driver with dmaengine_terminate_sync(). Fixes: 09c04466ce7e ("spi: lpspi: add dma mode support") Cc: stable@vger.kernel.org Signed-off-by: Carlos Song <carlos.song@nxp.com> --- Change for V2: - No change in v2. --- drivers/spi/spi-fsl-lpspi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index e201309f8aae..1a94a42fac31 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -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_all(controller->dma_tx); + dmaengine_terminate_sync(controller->dma_tx); return -EINVAL; } @@ -668,8 +668,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, transfer_timeout); if (!time_left) { dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n"); - dmaengine_terminate_all(controller->dma_tx); - dmaengine_terminate_all(controller->dma_rx); + dmaengine_terminate_sync(controller->dma_tx); + dmaengine_terminate_sync(controller->dma_rx); fsl_lpspi_reset(fsl_lpspi); return -ETIMEDOUT; } @@ -678,8 +678,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, transfer_timeout); if (!time_left) { dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n"); - dmaengine_terminate_all(controller->dma_tx); - dmaengine_terminate_all(controller->dma_rx); + dmaengine_terminate_sync(controller->dma_tx); + dmaengine_terminate_sync(controller->dma_rx); fsl_lpspi_reset(fsl_lpspi); return -ETIMEDOUT; } @@ -688,8 +688,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, fsl_lpspi->target_aborted) { dev_dbg(fsl_lpspi->dev, "I/O Error in DMA TX interrupted\n"); - dmaengine_terminate_all(controller->dma_tx); - dmaengine_terminate_all(controller->dma_rx); + dmaengine_terminate_sync(controller->dma_tx); + dmaengine_terminate_sync(controller->dma_rx); fsl_lpspi_reset(fsl_lpspi); return -EINTR; } @@ -698,8 +698,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, fsl_lpspi->target_aborted) { dev_dbg(fsl_lpspi->dev, "I/O Error in DMA RX interrupted\n"); - dmaengine_terminate_all(controller->dma_tx); - dmaengine_terminate_all(controller->dma_rx); + dmaengine_terminate_sync(controller->dma_tx); + dmaengine_terminate_sync(controller->dma_rx); fsl_lpspi_reset(fsl_lpspi); return -EINTR; } -- 2.43.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync 2026-05-20 9:43 ` [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync Carlos Song (OSS) @ 2026-05-20 16:52 ` Frank Li 0 siblings, 0 replies; 5+ messages in thread From: Frank Li @ 2026-05-20 16:52 UTC (permalink / raw) To: Carlos Song (OSS) Cc: broonie, xiaoning.wang, Fugang.duan, linux-spi, imx, linux-kernel, Carlos Song, stable On Wed, May 20, 2026 at 05:43:07PM +0800, Carlos Song (OSS) wrote: subject dmaengine_terminate_all() and dmaengine_terminate_sync(), all function need add () > From: Carlos Song <carlos.song@nxp.com> > > The terminate API dmaengine_terminate_all() has been deprecated, improve > driver with dmaengine_terminate_sync(). Nit: replace it with dmaengine_terminate_sync() Frank > > Fixes: 09c04466ce7e ("spi: lpspi: add dma mode support") > Cc: stable@vger.kernel.org > Signed-off-by: Carlos Song <carlos.song@nxp.com> > --- > Change for V2: > - No change in v2. > --- > drivers/spi/spi-fsl-lpspi.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c > index e201309f8aae..1a94a42fac31 100644 > --- a/drivers/spi/spi-fsl-lpspi.c > +++ b/drivers/spi/spi-fsl-lpspi.c > @@ -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_all(controller->dma_tx); > + dmaengine_terminate_sync(controller->dma_tx); > return -EINVAL; > } > > @@ -668,8 +668,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, > transfer_timeout); > if (!time_left) { > dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n"); > - dmaengine_terminate_all(controller->dma_tx); > - dmaengine_terminate_all(controller->dma_rx); > + dmaengine_terminate_sync(controller->dma_tx); > + dmaengine_terminate_sync(controller->dma_rx); > fsl_lpspi_reset(fsl_lpspi); > return -ETIMEDOUT; > } > @@ -678,8 +678,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, > transfer_timeout); > if (!time_left) { > dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n"); > - dmaengine_terminate_all(controller->dma_tx); > - dmaengine_terminate_all(controller->dma_rx); > + dmaengine_terminate_sync(controller->dma_tx); > + dmaengine_terminate_sync(controller->dma_rx); > fsl_lpspi_reset(fsl_lpspi); > return -ETIMEDOUT; > } > @@ -688,8 +688,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, > fsl_lpspi->target_aborted) { > dev_dbg(fsl_lpspi->dev, > "I/O Error in DMA TX interrupted\n"); > - dmaengine_terminate_all(controller->dma_tx); > - dmaengine_terminate_all(controller->dma_rx); > + dmaengine_terminate_sync(controller->dma_tx); > + dmaengine_terminate_sync(controller->dma_rx); > fsl_lpspi_reset(fsl_lpspi); > return -EINTR; > } > @@ -698,8 +698,8 @@ static int fsl_lpspi_dma_transfer(struct spi_controller *controller, > fsl_lpspi->target_aborted) { > dev_dbg(fsl_lpspi->dev, > "I/O Error in DMA RX interrupted\n"); > - dmaengine_terminate_all(controller->dma_tx); > - dmaengine_terminate_all(controller->dma_rx); > + dmaengine_terminate_sync(controller->dma_tx); > + dmaengine_terminate_sync(controller->dma_rx); > fsl_lpspi_reset(fsl_lpspi); > return -EINTR; > } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure 2026-05-20 9:43 [PATCH v2 0/2] spi: fsl-lpspi: fix DMA termination issues Carlos Song (OSS) 2026-05-20 9:43 ` [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync Carlos Song (OSS) @ 2026-05-20 9:43 ` Carlos Song (OSS) 2026-05-20 16:57 ` Frank Li 1 sibling, 1 reply; 5+ messages in thread From: Carlos Song (OSS) @ 2026-05-20 9:43 UTC (permalink / raw) To: Frank.Li, broonie, xiaoning.wang, Fugang.duan Cc: linux-spi, imx, linux-kernel, Carlos Song, stable From: Carlos Song <carlos.song@nxp.com> When dmaengine_prep_slave_sg() fails for the TX channel, the error path only 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. Fix this by also terminating 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> --- change for v2: - Add fix missing RX DMA termination on TX prepare failure. --- drivers/spi/spi-fsl-lpspi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 1a94a42fac31..906892453a84 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -647,6 +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_rx); dmaengine_terminate_sync(controller->dma_tx); return -EINVAL; } -- 2.43.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure 2026-05-20 9:43 ` [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure Carlos Song (OSS) @ 2026-05-20 16:57 ` Frank Li 0 siblings, 0 replies; 5+ messages in thread From: Frank Li @ 2026-05-20 16:57 UTC (permalink / raw) To: Carlos Song (OSS) Cc: broonie, xiaoning.wang, Fugang.duan, linux-spi, imx, linux-kernel, Carlos Song, stable On Wed, May 20, 2026 at 05:43:08PM +0800, Carlos Song (OSS) wrote: > From: Carlos Song <carlos.song@nxp.com> > > When dmaengine_prep_slave_sg() fails for the TX channel, the error path > only 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. > > Fix this by also terminating 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> > --- > change for v2: > - Add fix missing RX DMA termination on TX prepare failure. > --- > drivers/spi/spi-fsl-lpspi.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c > index 1a94a42fac31..906892453a84 100644 > --- a/drivers/spi/spi-fsl-lpspi.c > +++ b/drivers/spi/spi-fsl-lpspi.c > @@ -647,6 +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_rx); > dmaengine_terminate_sync(controller->dma_tx); Are you sure need terminate tx ? suppose tx have not submitted yet because failure to prep. I think it's should be typo previously, you intent temerate dma_rx insteand dma_tx at beginning. Frank > return -EINVAL; > } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-20 16:57 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-05-20 9:43 [PATCH v2 0/2] spi: fsl-lpspi: fix DMA termination issues Carlos Song (OSS) 2026-05-20 9:43 ` [PATCH v2 1/2] spi: fsl-lpspi: replace dmaengine_terminate_all with dmaengine_terminate_sync Carlos Song (OSS) 2026-05-20 16:52 ` Frank Li 2026-05-20 9:43 ` [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure Carlos Song (OSS) 2026-05-20 16:57 ` Frank Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®