Skip to contentSkip to conversation

Fix locking problem between em28xx and em28xx-dvb modules

PATCH New Chris Rankin 1 participant 1 message Aug 16, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix locking problem between em28xx and em28xx-dvb modules

Hi,

I've thought about this patch a bit more overnight, and it occurred to me that while em28xx_init_extension() now takes the device mutex followed by the device list mutex, my original fix would have had em28xx_register_extension() taking the device list mutex followed by the device mutex. And that sounds suspiciously like a potential deadlock to me. So I was wondering: does em28xx_register_extension() actually need to lock the device if the device list has already been locked?

I've also moved two printk()s outside the region where we hold the device list mutex, because locked bits should be as brief as possible and neither printk() does anything that needs the lock.

A new patch is attached, for review.

drivers/media/video/em28xx/em28xx-core.c renamed from drivers/media/video/em28xx/em28xx-core.c.orig +2 -2
@@ -1193,8 +1193,8 @@
 	list_for_each_entry(dev, &em28xx_devlist, devlist) {
 		ops->init(dev);
 	}
-	printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
 	mutex_unlock(&em28xx_devlist_mutex);
+	printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
 	return 0;
 }
 EXPORT_SYMBOL(em28xx_register_extension);
@@ -1207,9 +1207,9 @@
 	list_for_each_entry(dev, &em28xx_devlist, devlist) {
 		ops->fini(dev);
 	}
-	printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
 	list_del(&ops->next);
 	mutex_unlock(&em28xx_devlist_mutex);
+	printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
 }
 EXPORT_SYMBOL(em28xx_unregister_extension);
 
drivers/media/video/em28xx/em28xx-dvb.c renamed from drivers/media/video/em28xx/em28xx-dvb.c.orig +0 -2
@@ -542,7 +542,6 @@
 	dev->dvb = dvb;
 	dvb->fe[0] = dvb->fe[1] = NULL;
 
-	mutex_lock(&dev->lock);
 	em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
 	/* init frontend */
 	switch (dev->model) {
@@ -711,7 +710,6 @@
 	em28xx_info("Successfully loaded em28xx-dvb\n");
 ret:
 	em28xx_set_mode(dev, EM28XX_SUSPEND);
-	mutex_unlock(&dev->lock);
 	return result;
 
 out_free: