Skip to contentSkip to conversation

dmaengine: sf-pdma: Fix an error that calls callback twice

PATCH In review Brad Kim 3 participants 3 messages Aug 27, 2020 – Sep 3, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Brad Kim

author
#0 lore raw

PATCH 1/1 dmaengine: sf-pdma: Fix an error that calls callback twice

Because a callback is called twice when DMA transfer complete the second callback may be possible to access a freed memory if the first callback routines perform the dma_release_channel function. So this patch serialized the callback functions

---
 drivers/dma/sf-pdma/sf-pdma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/sf-pdma/sf-pdma.c +5 -5
index 6e530dca6d9e..754994087e5f 100644
@@ -295,7 +295,10 @@ static void sf_pdma_donebh_tasklet(unsigned long arg)
 	}
 	spin_unlock_irqrestore(&chan->lock, flags);
 
-	dmaengine_desc_get_callback_invoke(desc->async_tx, NULL);
+	spin_lock_irqsave(&chan->vchan.lock, flags);
+	list_del(&chan->desc->vdesc.node);
+	vchan_cookie_complete(&chan->desc->vdesc);
+	spin_unlock_irqrestore(&chan->vchan.lock, flags);
 }
 
 static void sf_pdma_errbh_tasklet(unsigned long arg)
@@ -332,8 +335,7 @@ static irqreturn_t sf_pdma_done_isr(int irq, void *dev_id)
 	residue = readq(regs->residue);
 
 	if (!residue) {
-		list_del(&chan->desc->vdesc.node);
-		vchan_cookie_complete(&chan->desc->vdesc);
+		tasklet_hi_schedule(&chan->done_tasklet);
 	} else {
 		/* submit next trascatioin if possible */
 		struct sf_pdma_desc *desc = chan->desc;
@@ -347,8 +349,6 @@ static irqreturn_t sf_pdma_done_isr(int irq, void *dev_id)
 
 	spin_unlock_irqrestore(&chan->vchan.lock, flags);
 
-	tasklet_hi_schedule(&chan->done_tasklet);
-
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): CAJivOr4iT-GZ_CcAHRPp9rjZbOaBXcX6j4KGQH=XuGoArZSnsg@mail.gmail.com

#2 lore raw

Looks good to me.

Tested-and-Reviewed-by Green Wan <[email protected]>
Quoted 55 lines · Green Wan

Looks good to me.

Tested-and-Reviewed-by Green Wan <[email protected]>
Quoted 49 lines · Brad Kim

Because a callback is called twice when DMA transfer complete the second callback may be possible to access a freed memory if the first callback routines perform the dma_release_channel function. So this patch serialized the callback functions

---
 drivers/dma/sf-pdma/sf-pdma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/sf-pdma/sf-pdma.c +5 -6
index 6e530dca6d9e..754994087e5f 100644
@@ -295,7 +295,10 @@ static void sf_pdma_donebh_tasklet(unsigned long arg)
        }
        spin_unlock_irqrestore(&chan->lock, flags);
 
-       dmaengine_desc_get_callback_invoke(desc->async_tx, NULL);
+       spin_lock_irqsave(&chan->vchan.lock, flags);
+       list_del(&chan->desc->vdesc.node);
+       vchan_cookie_complete(&chan->desc->vdesc);
+       spin_unlock_irqrestore(&chan->vchan.lock, flags);
 }
 
 static void sf_pdma_errbh_tasklet(unsigned long arg)
@@ -332,8 +335,7 @@ static irqreturn_t sf_pdma_done_isr(int irq, void *dev_id)
        residue = readq(regs->residue);
 
        if (!residue) {
-               list_del(&chan->desc->vdesc.node);
-               vchan_cookie_complete(&chan->desc->vdesc);
+               tasklet_hi_schedule(&chan->done_tasklet);
        } else {
                /* submit next trascatioin if possible */
                struct sf_pdma_desc *desc = chan->desc;
@@ -347,8 +349,6 @@ static irqreturn_t sf_pdma_done_isr(int irq, void *dev_id)
 
        spin_unlock_irqrestore(&chan->vchan.lock, flags);
 
-       tasklet_hi_schedule(&chan->done_tasklet);
-
        return IRQ_HANDLED;
 }
 
--

2.17.1

maintainer
#3 lore raw
In reply to Brad Kim

Hello Brad,

Quoted 6 lines · Brad Kim

Because a callback is called twice when DMA transfer complete the second callback may be possible to access a freed memory if the first callback routines perform the dma_release_channel function. So this patch serialized the callback functions

The patch came from Brad Kim <[email protected]> but was s-o-b [email protected]

I am not sure which one is correct but DCO clearly states that patch author Brad Kim <[email protected]> should sign off! You can add additional sign offs but that one is mandatory!

Thanks

Signature · 1 line
~Vinod