Commit 344d6c6b authored by Jonathan Nieder's avatar Jonathan Nieder Committed by Mauro Carvalho Chehab

[media] cx88: protect cx8802_devlist with a mutex

Add and use a mutex to protect the cx88-mpeg device list.  Previously
the BKL prevented races.

Based on work by Ben Hutchings <ben@decadent.org.uk>.
Tested-by: default avatarAndi Huber <hobrom@gmx.at>
Tested-by: default avatarMarlon de Boer <marlon@hyves.nl>
Signed-off-by: default avatarJonathan Nieder <jrnieder@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 1d6213ab
...@@ -78,6 +78,7 @@ static void flush_request_modules(struct cx8802_dev *dev) ...@@ -78,6 +78,7 @@ static void flush_request_modules(struct cx8802_dev *dev)
static LIST_HEAD(cx8802_devlist); static LIST_HEAD(cx8802_devlist);
static DEFINE_MUTEX(cx8802_mutex);
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
static int cx8802_start_dma(struct cx8802_dev *dev, static int cx8802_start_dma(struct cx8802_dev *dev,
...@@ -689,6 +690,8 @@ int cx8802_register_driver(struct cx8802_driver *drv) ...@@ -689,6 +690,8 @@ int cx8802_register_driver(struct cx8802_driver *drv)
return err; return err;
} }
mutex_lock(&cx8802_mutex);
list_for_each_entry(dev, &cx8802_devlist, devlist) { list_for_each_entry(dev, &cx8802_devlist, devlist) {
printk(KERN_INFO printk(KERN_INFO
"%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n", "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
...@@ -698,8 +701,10 @@ int cx8802_register_driver(struct cx8802_driver *drv) ...@@ -698,8 +701,10 @@ int cx8802_register_driver(struct cx8802_driver *drv)
/* Bring up a new struct for each driver instance */ /* Bring up a new struct for each driver instance */
driver = kzalloc(sizeof(*drv),GFP_KERNEL); driver = kzalloc(sizeof(*drv),GFP_KERNEL);
if (driver == NULL) if (driver == NULL) {
return -ENOMEM; err = -ENOMEM;
goto out;
}
/* Snapshot of the driver registration data */ /* Snapshot of the driver registration data */
drv->core = dev->core; drv->core = dev->core;
...@@ -722,7 +727,10 @@ int cx8802_register_driver(struct cx8802_driver *drv) ...@@ -722,7 +727,10 @@ int cx8802_register_driver(struct cx8802_driver *drv)
mutex_unlock(&drv->core->lock); mutex_unlock(&drv->core->lock);
} }
return i ? 0 : -ENODEV; err = i ? 0 : -ENODEV;
out:
mutex_unlock(&cx8802_mutex);
return err;
} }
int cx8802_unregister_driver(struct cx8802_driver *drv) int cx8802_unregister_driver(struct cx8802_driver *drv)
...@@ -736,6 +744,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv) ...@@ -736,6 +744,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird", drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive"); drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
mutex_lock(&cx8802_mutex);
list_for_each_entry(dev, &cx8802_devlist, devlist) { list_for_each_entry(dev, &cx8802_devlist, devlist) {
printk(KERN_INFO printk(KERN_INFO
"%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n", "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
...@@ -762,6 +772,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv) ...@@ -762,6 +772,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
mutex_unlock(&dev->core->lock); mutex_unlock(&dev->core->lock);
} }
mutex_unlock(&cx8802_mutex);
return err; return err;
} }
...@@ -799,7 +811,9 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev, ...@@ -799,7 +811,9 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev,
goto fail_free; goto fail_free;
INIT_LIST_HEAD(&dev->drvlist); INIT_LIST_HEAD(&dev->drvlist);
mutex_lock(&cx8802_mutex);
list_add_tail(&dev->devlist,&cx8802_devlist); list_add_tail(&dev->devlist,&cx8802_devlist);
mutex_unlock(&cx8802_mutex);
/* now autoload cx88-dvb or cx88-blackbird */ /* now autoload cx88-dvb or cx88-blackbird */
request_modules(dev); request_modules(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