]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
dmaengine: pl330: Acquire dmac's spinlock in pl330_tx_status
authorHsin-Yu Chao <hychao@chromium.org>
Tue, 23 Aug 2016 09:16:55 +0000 (17:16 +0800)
committerVinod Koul <vinod.koul@intel.com>
Fri, 9 Sep 2016 11:52:42 +0000 (17:22 +0530)
There is a racing when accessing dmac thread in pl330_tx_status that
the pl330_update is handling active request at the same time and
changing the status of descriptors. This could cause an invalid
transferred count from BUSY descriptor added up to the residual number.
Fix the bug by using the dmac's spinlock in pl330_tx_status to protect
thread resources from changing.
Note that the nested order of holding dmac's and dma_chan's spinlock is
consistent with the rest of the driver: dma_chan first and then dmac,
so it is safe from deadlock scenario.

Signed-off-by: Hsin-Yu Chao <hychao@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
drivers/dma/pl330.c

index 31e9c49e56049842a291f092ba9228cafa32aa8b..c4d61528072fe0d2663d650fa59f430ee372d3f9 100644 (file)
@@ -2287,6 +2287,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
                goto out;
 
        spin_lock_irqsave(&pch->lock, flags);
+       spin_lock(&pch->thread->dmac->lock);
 
        if (pch->thread->req_running != -1)
                running = pch->thread->req[pch->thread->req_running].desc;
@@ -2329,6 +2330,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
                if (desc->last)
                        residual = 0;
        }
+       spin_unlock(&pch->thread->dmac->lock);
        spin_unlock_irqrestore(&pch->lock, flags);
 
 out: