Skip to contentSkip to conversation

em28xx-video: Swap release order to avoid lock nesting

PATCH In review Ricardo Ribalda Delgado 2 participants 2 messages Nov 6, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 em28xx-video: Swap release order to avoid lock nesting

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.

---
 drivers/media/usb/em28xx/em28xx-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/em28xx/em28xx-video.c +1 -1
index 9d10334..b5c3360 100644
@@ -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,
Signature · 1 line
1.8.4.rc3
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Ricardo Ribalda Delgado

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.

---
 drivers/media/usb/em28xx/em28xx-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/em28xx/em28xx-video.c +0 -0
index 9d10334..b5c3360 100644

drivers/media/usb/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 1670

Quoted 9 lines
drivers/media/usb/em28xx/em28xx-video.c +1 -1
@@ -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,

Regards,

Hans