From: "Carlos Song (OSS)" <carlos.song@oss.nxp.com>
To: Frank.Li@nxp.com, broonie@kernel.org, xiaoning.wang@nxp.com,
Fugang.duan@nxp.com
Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev,
linux-kernel@vger.kernel.org, Carlos Song <carlos.song@nxp.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure
Date: Wed, 20 May 2026 17:43:08 +0800 [thread overview]
Message-ID: <20260520094308.2882892-3-carlos.song@oss.nxp.com> (raw)
In-Reply-To: <20260520094308.2882892-1-carlos.song@oss.nxp.com>
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
next prev parent reply other threads:[~2026-05-20 9:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Carlos Song (OSS) [this message]
2026-05-20 16:57 ` [PATCH v2 2/2] spi: fsl-lpspi: fix missing RX DMA termination on TX prepare failure 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=20260520094308.2882892-3-carlos.song@oss.nxp.com \
--to=carlos.song@oss.nxp.com \
--cc=Frank.Li@nxp.com \
--cc=Fugang.duan@nxp.com \
--cc=broonie@kernel.org \
--cc=carlos.song@nxp.com \
--cc=imx@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiaoning.wang@nxp.com \
/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
all inboxes | Powered by JetHome®