Skip to content

Commit baf6fd9

Browse files
pcercueivinodkoul
authored andcommitted
dmaengine: dma-jz4780: Fix race in jz4780_dma_tx_status
The jz4780_dma_tx_status() function would check if a channel's cookie state was set to 'completed', and if not, it would enter the critical section. However, in that time frame, the jz4780_dma_chan_irq() function was able to set the cookie to 'completed', and clear the jzchan->vchan pointer, which was deferenced in the critical section of the first function. Fix this race by checking the channel's cookie state after entering the critical function and not before. Fixes: d894fc6 ("dmaengine: jz4780: add driver for the Ingenic JZ4780 DMA controller") Cc: stable@vger.kernel.org # v4.0 Signed-off-by: Paul Cercueil <paul@crapouillou.net> Reported-by: Artur Rojek <contact@artur-rojek.eu> Tested-by: Artur Rojek <contact@artur-rojek.eu> Link: https://lore.kernel.org/r/20201004140307.885556-1-paul@crapouillou.net Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent a841592 commit baf6fd9

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/dma/dma-jz4780.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,11 @@ static enum dma_status jz4780_dma_tx_status(struct dma_chan *chan,
639639
unsigned long flags;
640640
unsigned long residue = 0;
641641

642+
spin_lock_irqsave(&jzchan->vchan.lock, flags);
643+
642644
status = dma_cookie_status(chan, cookie, txstate);
643645
if ((status == DMA_COMPLETE) || (txstate == NULL))
644-
return status;
645-
646-
spin_lock_irqsave(&jzchan->vchan.lock, flags);
646+
goto out_unlock_irqrestore;
647647

648648
vdesc = vchan_find_desc(&jzchan->vchan, cookie);
649649
if (vdesc) {
@@ -660,6 +660,7 @@ static enum dma_status jz4780_dma_tx_status(struct dma_chan *chan,
660660
&& jzchan->desc->status & (JZ_DMA_DCS_AR | JZ_DMA_DCS_HLT))
661661
status = DMA_ERROR;
662662

663+
out_unlock_irqrestore:
663664
spin_unlock_irqrestore(&jzchan->vchan.lock, flags);
664665
return status;
665666
}

0 commit comments

Comments
 (0)