Commit e491cbc8 authored by Alan Cox's avatar Alan Cox Committed by Mauro Carvalho Chehab

V4L/DVB (4707): 4linux: complete conversion to hotplug safe PCI API

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent a868b45d
...@@ -1278,9 +1278,7 @@ find_zr36057 (void) ...@@ -1278,9 +1278,7 @@ find_zr36057 (void)
zoran_num = 0; zoran_num = 0;
while (zoran_num < BUZ_MAX && while (zoran_num < BUZ_MAX &&
(dev = (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
pci_find_device(PCI_VENDOR_ID_ZORAN,
PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
card_num = card[zoran_num]; card_num = card[zoran_num];
zr = &zoran[zoran_num]; zr = &zoran[zoran_num];
memset(zr, 0, sizeof(struct zoran)); // Just in case if previous cycle failed memset(zr, 0, sizeof(struct zoran)); // Just in case if previous cycle failed
...@@ -1541,7 +1539,8 @@ find_zr36057 (void) ...@@ -1541,7 +1539,8 @@ find_zr36057 (void)
goto zr_detach_vfe; goto zr_detach_vfe;
} }
} }
/* Success so keep the pci_dev referenced */
pci_dev_get(zr->pci_dev);
zoran_num++; zoran_num++;
continue; continue;
...@@ -1563,6 +1562,9 @@ find_zr36057 (void) ...@@ -1563,6 +1562,9 @@ find_zr36057 (void)
iounmap(zr->zr36057_mem); iounmap(zr->zr36057_mem);
continue; continue;
} }
if (dev) /* Clean up ref count on early exit */
pci_dev_put(dev);
if (zoran_num == 0) { if (zoran_num == 0) {
dprintk(1, KERN_INFO "No known MJPEG cards found.\n"); dprintk(1, KERN_INFO "No known MJPEG cards found.\n");
} }
......
...@@ -1840,16 +1840,16 @@ int __init find_zoran(void) ...@@ -1840,16 +1840,16 @@ int __init find_zoran(void)
struct zoran *ztv; struct zoran *ztv;
struct pci_dev *dev = NULL; struct pci_dev *dev = NULL;
unsigned char revision; unsigned char revision;
int zoran_num=0; int zoran_num = 0;
while ((dev = pci_find_device(PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120, dev))) while ((dev = pci_get_device(PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120, dev)))
{ {
/* Ok, a ZR36120/ZR36125 found! */ /* Ok, a ZR36120/ZR36125 found! */
ztv = &zorans[zoran_num]; ztv = &zorans[zoran_num];
ztv->dev = dev; ztv->dev = dev;
if (pci_enable_device(dev)) if (pci_enable_device(dev))
return -EIO; continue;
pci_read_config_byte(dev, PCI_CLASS_REVISION, &revision); pci_read_config_byte(dev, PCI_CLASS_REVISION, &revision);
printk(KERN_INFO "zoran: Zoran %x (rev %d) ", printk(KERN_INFO "zoran: Zoran %x (rev %d) ",
...@@ -1867,17 +1867,18 @@ int __init find_zoran(void) ...@@ -1867,17 +1867,18 @@ int __init find_zoran(void)
{ {
iounmap(ztv->zoran_mem); iounmap(ztv->zoran_mem);
printk(KERN_ERR "zoran: Bad irq number or handler\n"); printk(KERN_ERR "zoran: Bad irq number or handler\n");
return -EINVAL; continue;
} }
if (result==-EBUSY) if (result==-EBUSY)
printk(KERN_ERR "zoran: IRQ %d busy, change your PnP config in BIOS\n",dev->irq); printk(KERN_ERR "zoran: IRQ %d busy, change your PnP config in BIOS\n",dev->irq);
if (result < 0) { if (result < 0) {
iounmap(ztv->zoran_mem); iounmap(ztv->zoran_mem);
return result; continue;
} }
/* Enable bus-mastering */ /* Enable bus-mastering */
pci_set_master(dev); pci_set_master(dev);
/* Keep a reference */
pci_dev_get(dev);
zoran_num++; zoran_num++;
} }
if(zoran_num) if(zoran_num)
...@@ -2041,6 +2042,9 @@ void release_zoran(int max) ...@@ -2041,6 +2042,9 @@ void release_zoran(int max)
if (ztv->zoran_mem) if (ztv->zoran_mem)
iounmap(ztv->zoran_mem); iounmap(ztv->zoran_mem);
/* Drop PCI device */
pci_dev_put(ztv->dev);
video_unregister_device(&ztv->video_dev); video_unregister_device(&ztv->video_dev);
video_unregister_device(&ztv->vbi_dev); video_unregister_device(&ztv->vbi_dev);
} }
...@@ -2057,13 +2061,12 @@ int __init zr36120_init(void) ...@@ -2057,13 +2061,12 @@ int __init zr36120_init(void)
handle_chipset(); handle_chipset();
zoran_cards = find_zoran(); zoran_cards = find_zoran();
if (zoran_cards<0) if (zoran_cards <= 0)
/* no cards found, no need for a driver */
return -EIO; return -EIO;
/* initialize Zorans */ /* initialize Zorans */
for (card=0; card<zoran_cards; card++) { for (card=0; card<zoran_cards; card++) {
if (init_zoran(card)<0) { if (init_zoran(card) < 0) {
/* only release the zorans we have registered */ /* only release the zorans we have registered */
release_zoran(card); release_zoran(card);
return -EIO; return -EIO;
......
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