* [PATCH] spi: dw: Unconditionally stop DMA on errors
@ 2026-10-03 16:18 Changhuang Liang
2026-10-05 14:11 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Changhuang Liang @ 2026-10-03 16:18 UTC (permalink / raw)
To: Mark Brown; +Cc: Serge Semin, linux-spi, linux-kernel, Changhuang Liang
dw_spi_dma_stop() and dw_spi_enh_mem_dma_stop() only terminate a DMA
channel when the corresponding busy flag is set. They are only called
on error paths, where the flags are not guaranteed to match the state
of the DMA engine, so a channel may be left running.
Terminate the channels and clear the busy flags unconditionally in
dw_spi_dma_stop(). A channel may be missing when only one DMA channel
is available, so check for that.
With that the enhanced memory operation variant is no longer needed,
use dw_spi_dma_stop() there as well.
Suggested-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
drivers/spi/spi-dw-dma.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c
index a86039057988..b706770334a6 100644
--- a/drivers/spi/spi-dw-dma.c
+++ b/drivers/spi/spi-dw-dma.c
@@ -718,14 +718,18 @@ static int dw_spi_dma_transfer(struct dw_spi *dws, struct spi_transfer *xfer)
static void dw_spi_dma_stop(struct dw_spi *dws)
{
- if (test_bit(DW_SPI_TX_BUSY, &dws->dma_chan_busy)) {
+ /*
+ * This is only called on errors, so don't rely on the busy flags
+ * being in sync with the DMA engine state. A channel may be missing
+ * when only one DMA channel is available.
+ */
+ if (dws->txchan)
dmaengine_terminate_sync(dws->txchan);
- clear_bit(DW_SPI_TX_BUSY, &dws->dma_chan_busy);
- }
- if (test_bit(DW_SPI_RX_BUSY, &dws->dma_chan_busy)) {
+ if (dws->rxchan)
dmaengine_terminate_sync(dws->rxchan);
- clear_bit(DW_SPI_RX_BUSY, &dws->dma_chan_busy);
- }
+
+ clear_bit(DW_SPI_TX_BUSY, &dws->dma_chan_busy);
+ clear_bit(DW_SPI_RX_BUSY, &dws->dma_chan_busy);
}
/*
@@ -844,21 +848,6 @@ static bool dw_spi_enh_mem_can_dma(struct spi_controller *ctlr)
return dws->dma_addr_widths & BIT(dma_bus_width);
}
-static void dw_spi_enh_mem_dma_stop(struct dw_spi *dws)
-{
- if (dws->tx_dir) {
- if (test_bit(DW_SPI_TX_BUSY, &dws->dma_chan_busy)) {
- dmaengine_terminate_sync(dws->txchan);
- clear_bit(DW_SPI_TX_BUSY, &dws->dma_chan_busy);
- }
- } else {
- if (test_bit(DW_SPI_RX_BUSY, &dws->dma_chan_busy)) {
- dmaengine_terminate_sync(dws->rxchan);
- clear_bit(DW_SPI_RX_BUSY, &dws->dma_chan_busy);
- }
- }
-}
-
static int dw_spi_enh_mem_dma_transfer(struct spi_mem *mem, const struct spi_mem_op *op)
{
struct spi_controller *ctlr = mem->spi->controller;
@@ -893,7 +882,7 @@ static int dw_spi_enh_mem_dma_transfer(struct spi_mem *mem, const struct spi_mem
}
if (ret)
- dw_spi_enh_mem_dma_stop(dws);
+ dw_spi_dma_stop(dws);
else
ret = dw_spi_check_status(dws, true);
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] spi: dw: Unconditionally stop DMA on errors
2026-10-03 16:18 [PATCH] spi: dw: Unconditionally stop DMA on errors Changhuang Liang
@ 2026-10-05 14:11 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-10-05 14:11 UTC (permalink / raw)
To: Changhuang Liang; +Cc: Serge Semin, linux-spi, linux-kernel
On Sat, 03 Oct 2026 09:18:07 -0700, Changhuang Liang wrote:
> spi: dw: Unconditionally stop DMA on errors
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4
Thanks!
[1/1] spi: dw: Unconditionally stop DMA on errors
https://git.kernel.org/broonie/spi/c/37bc964c2da7
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-06 8:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-03 16:18 [PATCH] spi: dw: Unconditionally stop DMA on errors Changhuang Liang
2026-10-05 14:11 ` Mark Brown
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®