spi: dw: Unconditionally stop DMA on errors
PATCH 1/1 spi: dw: Unconditionally stop DMA on errors
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.
--- drivers/spi/spi-dw-dma.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
drivers/spi/spi-dw-dma.c +11 -22
@@ -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);
Signature · 1 line
2.25.1
Mark Brown
maintainerQuoted 1 line · Changhuang Liang
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