Re: [PATCH v8 3/9] dmaengine: dw-axi-dmac: retain descriptors when termination times out

From: Frank Li

Date: Thu Nov 19 2026 - 11:18:47 EST


On Thu, Nov 19, 2026 at 09:00:58AM -0700, James Hilliard wrote:
> dma_chan_terminate_all() warns when the channel enable bit does not clear,
> but then frees the descriptors and returns success. Its synchronize
> callback only drains virtual-channel callbacks, so terminate_sync() can
> also report success while hardware still accesses the transfer.
>
> Return the polling error before detaching descriptors or changing the
> peripheral routing. This keeps the transfer resources available while
> the channel remains enabled and lets the caller retry termination without
> treating the timeout as a successful stop.
>
> Hold the channel lock across disabling, polling and descriptor detachment
> so an interrupt handler cannot restart the channel between the stop check
> and cleanup.
>
> Fixes: 1deb96c0fa58 ("dmaegine: dw-axi-dmac: Support device_prep_dma_cyclic()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---

Reviewed-by: Frank Li <Frank.Li@xxxxxxx>

> drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 37 ++++++++++++++------------
> 1 file changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index f17a71183050..def591fc75ce 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -9,6 +9,7 @@
>
> #include <linux/bitfield.h>
> #include <linux/bitops.h>
> +#include <linux/cleanup.h>
> #include <linux/delay.h>
> #include <linux/device.h>
> #include <linux/dmaengine.h>
> @@ -1180,30 +1181,32 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
> static int dma_chan_terminate_all(struct dma_chan *dchan)
> {
> struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
> - unsigned long flags;
> - bool enabled;
> int ret;
> LIST_HEAD(head);
>
> - axi_chan_disable(chan);
> -
> - ret = read_poll_timeout_atomic(axi_chan_is_hw_enable, enabled, !enabled,
> - 1 * USEC_PER_MSEC, 50 * USEC_PER_MSEC,
> - false, chan);
> - if (ret)
> - dev_warn(dmaengine_chan_dev(dchan),
> - "%s failed to stop\n", axi_chan_name(chan));
> + scoped_guard(spinlock_irqsave, &chan->vc.lock) {
> + bool enabled;
>
> - if (chan->direction != DMA_MEM_TO_MEM)
> - dw_axi_dma_set_hw_channel(chan, false);
> - if (chan->direction == DMA_MEM_TO_DEV)
> - dw_axi_dma_set_byte_halfword(chan, false);
> + axi_chan_disable(chan);
> + ret = read_poll_timeout_atomic(axi_chan_is_hw_enable, enabled, !enabled,
> + 1 * USEC_PER_MSEC, 50 * USEC_PER_MSEC,
> + false, chan);
> + if (ret)
> + break;
>
> - spin_lock_irqsave(&chan->vc.lock, flags);
> + if (chan->direction != DMA_MEM_TO_MEM)
> + dw_axi_dma_set_hw_channel(chan, false);
> + if (chan->direction == DMA_MEM_TO_DEV)
> + dw_axi_dma_set_byte_halfword(chan, false);
>
> - vchan_get_all_descriptors(&chan->vc, &head);
> + vchan_get_all_descriptors(&chan->vc, &head);
> + }
>
> - spin_unlock_irqrestore(&chan->vc.lock, flags);
> + if (ret) {
> + dev_warn(dmaengine_chan_dev(dchan),
> + "%s failed to stop\n", axi_chan_name(chan));
> + return ret;
> + }
>
> vchan_dma_desc_free_list(&chan->vc, &head);
>
>
> --
> 2.53.0
>