Skip to content

Commit 855c2e1

Browse files
Jan Kuligavinodkoul
authored andcommitted
dmaengine: xilinx: xdma: Rework xdma_terminate_all()
Simplify xdma_xfer_stop(). Stop the dma engine and clear its status register unconditionally - just do what its name states. This change also allows to call it without grabbing a lock, which minimizes the total time spent with a spinlock held. Delete the currently processed vd.node from the vc.desc_issued list prior to passing it to vchan_terminate_vdesc(). In case there's more than one descriptor pending on vc.desc_issued list, calling vchan_terminate_desc() results in losing the link between vc.desc_issued list head and the second descriptor on the list. Doing so results in resources leakege, as vchan_dma_desc_free_list() won't be able to properly free memory resources attached to descriptors, resulting in dma_pool_destroy() failure. Don't call vchan_dma_desc_free_list() from within xdma_terminate_all(). Move all terminated descriptors to the vc.desc_terminated list instead. This allows to postpone freeing memory resources associated with descriptors until the call to vchan_synchronize(), which is called from xdma_synchronize() callback. This is the right way to do it - xdma_terminate_all() should return as soon as possible, while freeing resources (that may be time consuming in case of large number of descriptors) can be done safely later. Fixes: f5c392d ("dmaengine: xilinx: xdma: Add terminate_all/synchronize callbacks") Signed-off-by: Jan Kuliga <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e5bc76b commit 855c2e1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

drivers/dma/xilinx/xdma.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,20 @@ static int xdma_xfer_start(struct xdma_chan *xchan)
379379
*/
380380
static int xdma_xfer_stop(struct xdma_chan *xchan)
381381
{
382-
struct virt_dma_desc *vd = vchan_next_desc(&xchan->vchan);
383-
struct xdma_device *xdev = xchan->xdev_hdl;
384382
int ret;
385-
386-
if (!vd || !xchan->busy)
387-
return -EINVAL;
383+
u32 val;
384+
struct xdma_device *xdev = xchan->xdev_hdl;
388385

389386
/* clear run stop bit to prevent any further auto-triggering */
390387
ret = regmap_write(xdev->rmap, xchan->base + XDMA_CHAN_CONTROL_W1C,
391388
CHAN_CTRL_RUN_STOP);
392389
if (ret)
393390
return ret;
394391

395-
xchan->busy = false;
392+
/* Clear the channel status register */
393+
ret = regmap_read(xdev->rmap, xchan->base + XDMA_CHAN_STATUS_RC, &val);
394+
if (ret)
395+
return ret;
396396

397397
return 0;
398398
}
@@ -505,25 +505,25 @@ static void xdma_issue_pending(struct dma_chan *chan)
505505
static int xdma_terminate_all(struct dma_chan *chan)
506506
{
507507
struct xdma_chan *xdma_chan = to_xdma_chan(chan);
508-
struct xdma_desc *desc = NULL;
509508
struct virt_dma_desc *vd;
510509
unsigned long flags;
511510
LIST_HEAD(head);
512511

513-
spin_lock_irqsave(&xdma_chan->vchan.lock, flags);
514512
xdma_xfer_stop(xdma_chan);
515513

514+
spin_lock_irqsave(&xdma_chan->vchan.lock, flags);
515+
516+
xdma_chan->busy = false;
516517
vd = vchan_next_desc(&xdma_chan->vchan);
517-
if (vd)
518-
desc = to_xdma_desc(vd);
519-
if (desc) {
520-
dma_cookie_complete(&desc->vdesc.tx);
521-
vchan_terminate_vdesc(&desc->vdesc);
518+
if (vd) {
519+
list_del(&vd->node);
520+
dma_cookie_complete(&vd->tx);
521+
vchan_terminate_vdesc(vd);
522522
}
523-
524523
vchan_get_all_descriptors(&xdma_chan->vchan, &head);
524+
list_splice_tail(&head, &xdma_chan->vchan.desc_terminated);
525+
525526
spin_unlock_irqrestore(&xdma_chan->vchan.lock, flags);
526-
vchan_dma_desc_free_list(&xdma_chan->vchan, &head);
527527

528528
return 0;
529529
}

0 commit comments

Comments
 (0)