em28xx-video: Swap release order to avoid lock nesting

Message ID 1383727175-26052-1-git-send-email-ricardo.ribalda@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Hans Verkuil
Headers

Commit Message

Ricardo Ribalda Delgado Nov. 6, 2013, 8:39 a.m. UTC
  vb2_fop_release might take the video queue mutex lock.
In order to avoid nesting mutexes the private mutex is taken after the
fop_release has finished.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Hans Verkuil Nov. 6, 2013, 9:08 a.m. UTC | #1
On 11/06/13 09:39, Ricardo Ribalda Delgado wrote:
> vb2_fop_release might take the video queue mutex lock.
> In order to avoid nesting mutexes the private mutex is taken after the
> fop_release has finished.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  drivers/media/usb/em28xx/em28xx-video.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
> index 9d10334..b5c3360 100644
> --- a/drivers/media/usb/em28xx/em28xx-video.c
> +++ b/drivers/media/usb/em28xx/em28xx-video.c
> @@ -1663,8 +1663,8 @@ static int em28xx_v4l2_close(struct file *filp)
>  
>  	em28xx_videodbg("users=%d\n", dev->users);
>  
> -	mutex_lock(&dev->lock);
>  	vb2_fop_release(filp);
> +	mutex_lock(&dev->lock);
>  
>  	if (dev->users == 1) {
>  		/* the device is already disconnect,
> 

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 9d10334..b5c3360 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -1663,8 +1663,8 @@  static int em28xx_v4l2_close(struct file *filp)
 
 	em28xx_videodbg("users=%d\n", dev->users);
 
-	mutex_lock(&dev->lock);
 	vb2_fop_release(filp);
+	mutex_lock(&dev->lock);
 
 	if (dev->users == 1) {
 		/* the device is already disconnect,