diff mbox series

[1/5] dmaengine: virt-dma: Add missing locking around list operations

Message ID 20191206135344.29330-2-s.hauer@pengutronix.de (mailing list archive)
State Changes Requested
Headers show
Series virt-dma and i.MX SDMA fixes | expand

Commit Message

Sascha Hauer Dec. 6, 2019, 1:53 p.m. UTC
All list operations are protected by &vc->lock. As vchan_vdesc_fini()
is called unlocked add the missing locking around the list operations.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/dma/virt-dma.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Peter Ujfalusi Dec. 9, 2019, 7:38 a.m. UTC | #1
Hi Sascha,

On 06/12/2019 15.53, Sascha Hauer wrote:
> All list operations are protected by &vc->lock. As vchan_vdesc_fini()
> is called unlocked add the missing locking around the list operations.

At this commit the vhcan_vdesc_fini() _is_ called when the lock is held
via vchan_terminate_vdesc() which must be called with the lock held...

Swap patch 1 and 2.

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/dma/virt-dma.h | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h
> index ab158bac03a7..41883ee2c29f 100644
> --- a/drivers/dma/virt-dma.h
> +++ b/drivers/dma/virt-dma.h
> @@ -113,10 +113,15 @@ static inline void vchan_vdesc_fini(struct virt_dma_desc *vd)
>  {
>  	struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
>  
> -	if (dmaengine_desc_test_reuse(&vd->tx))
> +	if (dmaengine_desc_test_reuse(&vd->tx)) {
> +		unsigned long flags;
> +
> +		spin_lock_irqsave(&vc->lock, flags);
>  		list_add(&vd->node, &vc->desc_allocated);
> -	else
> +		spin_unlock_irqrestore(&vc->lock, flags);
> +	} else {
>  		vc->desc_free(vd);
> +	}
>  }
>  
>  /**
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Sascha Hauer Dec. 10, 2019, 11:56 a.m. UTC | #2
On Mon, Dec 09, 2019 at 09:38:17AM +0200, Peter Ujfalusi wrote:
> Hi Sascha,
> 
> On 06/12/2019 15.53, Sascha Hauer wrote:
> > All list operations are protected by &vc->lock. As vchan_vdesc_fini()
> > is called unlocked add the missing locking around the list operations.
> 
> At this commit the vhcan_vdesc_fini() _is_ called when the lock is held
> via vchan_terminate_vdesc() which must be called with the lock held...
> 
> Swap patch 1 and 2.

Right, will do.

Sascha
diff mbox series

Patch

diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h
index ab158bac03a7..41883ee2c29f 100644
--- a/drivers/dma/virt-dma.h
+++ b/drivers/dma/virt-dma.h
@@ -113,10 +113,15 @@  static inline void vchan_vdesc_fini(struct virt_dma_desc *vd)
 {
 	struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
 
-	if (dmaengine_desc_test_reuse(&vd->tx))
+	if (dmaengine_desc_test_reuse(&vd->tx)) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&vc->lock, flags);
 		list_add(&vd->node, &vc->desc_allocated);
-	else
+		spin_unlock_irqrestore(&vc->lock, flags);
+	} else {
 		vc->desc_free(vd);
+	}
 }
 
 /**