Commit 5013318c authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB: em28xx: fix locks during dvb init sequence

Serialize DVB initialization, to avoid it to happen while analog
initialization is still happening.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent d922b8ea
...@@ -1178,21 +1178,18 @@ void em28xx_add_into_devlist(struct em28xx *dev) ...@@ -1178,21 +1178,18 @@ void em28xx_add_into_devlist(struct em28xx *dev)
*/ */
static LIST_HEAD(em28xx_extension_devlist); static LIST_HEAD(em28xx_extension_devlist);
static DEFINE_MUTEX(em28xx_extension_devlist_lock);
int em28xx_register_extension(struct em28xx_ops *ops) int em28xx_register_extension(struct em28xx_ops *ops)
{ {
struct em28xx *dev = NULL; struct em28xx *dev = NULL;
mutex_lock(&em28xx_devlist_mutex); mutex_lock(&em28xx_devlist_mutex);
mutex_lock(&em28xx_extension_devlist_lock);
list_add_tail(&ops->next, &em28xx_extension_devlist); list_add_tail(&ops->next, &em28xx_extension_devlist);
list_for_each_entry(dev, &em28xx_devlist, devlist) { list_for_each_entry(dev, &em28xx_devlist, devlist) {
if (dev) if (dev)
ops->init(dev); ops->init(dev);
} }
printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name); printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
mutex_unlock(&em28xx_extension_devlist_lock);
mutex_unlock(&em28xx_devlist_mutex); mutex_unlock(&em28xx_devlist_mutex);
return 0; return 0;
} }
...@@ -1208,10 +1205,8 @@ void em28xx_unregister_extension(struct em28xx_ops *ops) ...@@ -1208,10 +1205,8 @@ void em28xx_unregister_extension(struct em28xx_ops *ops)
ops->fini(dev); ops->fini(dev);
} }
mutex_lock(&em28xx_extension_devlist_lock);
printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name); printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
list_del(&ops->next); list_del(&ops->next);
mutex_unlock(&em28xx_extension_devlist_lock);
mutex_unlock(&em28xx_devlist_mutex); mutex_unlock(&em28xx_devlist_mutex);
} }
EXPORT_SYMBOL(em28xx_unregister_extension); EXPORT_SYMBOL(em28xx_unregister_extension);
...@@ -1220,26 +1215,26 @@ void em28xx_init_extension(struct em28xx *dev) ...@@ -1220,26 +1215,26 @@ void em28xx_init_extension(struct em28xx *dev)
{ {
struct em28xx_ops *ops = NULL; struct em28xx_ops *ops = NULL;
mutex_lock(&em28xx_extension_devlist_lock); mutex_lock(&em28xx_devlist_mutex);
if (!list_empty(&em28xx_extension_devlist)) { if (!list_empty(&em28xx_extension_devlist)) {
list_for_each_entry(ops, &em28xx_extension_devlist, next) { list_for_each_entry(ops, &em28xx_extension_devlist, next) {
if (ops->init) if (ops->init)
ops->init(dev); ops->init(dev);
} }
} }
mutex_unlock(&em28xx_extension_devlist_lock); mutex_unlock(&em28xx_devlist_mutex);
} }
void em28xx_close_extension(struct em28xx *dev) void em28xx_close_extension(struct em28xx *dev)
{ {
struct em28xx_ops *ops = NULL; struct em28xx_ops *ops = NULL;
mutex_lock(&em28xx_extension_devlist_lock); mutex_lock(&em28xx_devlist_mutex);
if (!list_empty(&em28xx_extension_devlist)) { if (!list_empty(&em28xx_extension_devlist)) {
list_for_each_entry(ops, &em28xx_extension_devlist, next) { list_for_each_entry(ops, &em28xx_extension_devlist, next) {
if (ops->fini) if (ops->fini)
ops->fini(dev); ops->fini(dev);
} }
} }
mutex_unlock(&em28xx_extension_devlist_lock); mutex_unlock(&em28xx_devlist_mutex);
} }
...@@ -467,6 +467,7 @@ static int dvb_init(struct em28xx *dev) ...@@ -467,6 +467,7 @@ static int dvb_init(struct em28xx *dev)
} }
dev->dvb = dvb; dev->dvb = dvb;
mutex_lock(&dev->lock);
em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
/* init frontend */ /* init frontend */
switch (dev->model) { switch (dev->model) {
...@@ -590,15 +591,16 @@ static int dvb_init(struct em28xx *dev) ...@@ -590,15 +591,16 @@ static int dvb_init(struct em28xx *dev)
if (result < 0) if (result < 0)
goto out_free; goto out_free;
em28xx_set_mode(dev, EM28XX_SUSPEND);
em28xx_info("Successfully loaded em28xx-dvb\n"); em28xx_info("Successfully loaded em28xx-dvb\n");
return 0; ret:
em28xx_set_mode(dev, EM28XX_SUSPEND);
mutex_unlock(&dev->lock);
return result;
out_free: out_free:
em28xx_set_mode(dev, EM28XX_SUSPEND);
kfree(dvb); kfree(dvb);
dev->dvb = NULL; dev->dvb = NULL;
return result; goto ret;
} }
static int dvb_fini(struct em28xx *dev) static int dvb_fini(struct em28xx *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment