Commit dd8e9ed6 authored by Alan Cox's avatar Alan Cox Committed by David Woodhouse

[MTD] Switch to pci_get_device and do ref counting

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 668040fc
...@@ -674,7 +674,7 @@ static int __init init_pmc551(void) ...@@ -674,7 +674,7 @@ static int __init init_pmc551(void)
*/ */
for( count = 0; count < MAX_MTD_DEVICES; count++ ) { for( count = 0; count < MAX_MTD_DEVICES; count++ ) {
if ((PCI_Device = pci_find_device(PCI_VENDOR_ID_V3_SEMI, if ((PCI_Device = pci_get_device(PCI_VENDOR_ID_V3_SEMI,
PCI_DEVICE_ID_V3_SEMI_V370PDC, PCI_DEVICE_ID_V3_SEMI_V370PDC,
PCI_Device ) ) == NULL) { PCI_Device ) ) == NULL) {
break; break;
...@@ -783,6 +783,10 @@ static int __init init_pmc551(void) ...@@ -783,6 +783,10 @@ static int __init init_pmc551(void)
kfree(mtd); kfree(mtd);
break; break;
} }
/* Keep a reference as the add_mtd_device worked */
pci_dev_get(PCI_Device);
printk(KERN_NOTICE "Registered pmc551 memory device.\n"); printk(KERN_NOTICE "Registered pmc551 memory device.\n");
printk(KERN_NOTICE "Mapped %dM of memory from 0x%p to 0x%p\n", printk(KERN_NOTICE "Mapped %dM of memory from 0x%p to 0x%p\n",
priv->asize>>20, priv->asize>>20,
...@@ -797,6 +801,10 @@ static int __init init_pmc551(void) ...@@ -797,6 +801,10 @@ static int __init init_pmc551(void)
found++; found++;
} }
/* Exited early, reference left over */
if (PCI_Device)
pci_dev_put(PCI_Device);
if( !pmc551list ) { if( !pmc551list ) {
printk(KERN_NOTICE "pmc551: not detected\n"); printk(KERN_NOTICE "pmc551: not detected\n");
return -ENODEV; return -ENODEV;
...@@ -824,6 +832,7 @@ static void __exit cleanup_pmc551(void) ...@@ -824,6 +832,7 @@ static void __exit cleanup_pmc551(void)
priv->asize>>20, priv->start); priv->asize>>20, priv->start);
iounmap (priv->start); iounmap (priv->start);
} }
pci_dev_put(priv->dev);
kfree (mtd->priv); kfree (mtd->priv);
del_mtd_device (mtd); del_mtd_device (mtd);
......
...@@ -57,6 +57,7 @@ static void amd76xrom_cleanup(struct amd76xrom_window *window) ...@@ -57,6 +57,7 @@ static void amd76xrom_cleanup(struct amd76xrom_window *window)
/* Disable writes through the rom window */ /* Disable writes through the rom window */
pci_read_config_byte(window->pdev, 0x40, &byte); pci_read_config_byte(window->pdev, 0x40, &byte);
pci_write_config_byte(window->pdev, 0x40, byte & ~1); pci_write_config_byte(window->pdev, 0x40, byte & ~1);
pci_dev_put(window->pdev);
} }
/* Free all of the mtd devices */ /* Free all of the mtd devices */
...@@ -91,7 +92,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev, ...@@ -91,7 +92,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
struct amd76xrom_map_info *map = NULL; struct amd76xrom_map_info *map = NULL;
unsigned long map_top; unsigned long map_top;
/* Remember the pci dev I find the window in */ /* Remember the pci dev I find the window in - already have a ref */
window->pdev = pdev; window->pdev = pdev;
/* Assume the rom window is properly setup, and find it's size */ /* Assume the rom window is properly setup, and find it's size */
...@@ -302,7 +303,7 @@ static int __init init_amd76xrom(void) ...@@ -302,7 +303,7 @@ static int __init init_amd76xrom(void)
struct pci_device_id *id; struct pci_device_id *id;
pdev = NULL; pdev = NULL;
for(id = amd76xrom_pci_tbl; id->vendor; id++) { for(id = amd76xrom_pci_tbl; id->vendor; id++) {
pdev = pci_find_device(id->vendor, id->device, NULL); pdev = pci_get_device(id->vendor, id->device, NULL);
if (pdev) { if (pdev) {
break; break;
} }
......
...@@ -61,6 +61,7 @@ static void ichxrom_cleanup(struct ichxrom_window *window) ...@@ -61,6 +61,7 @@ static void ichxrom_cleanup(struct ichxrom_window *window)
/* Disable writes through the rom window */ /* Disable writes through the rom window */
pci_read_config_word(window->pdev, BIOS_CNTL, &word); pci_read_config_word(window->pdev, BIOS_CNTL, &word);
pci_write_config_word(window->pdev, BIOS_CNTL, word & ~1); pci_write_config_word(window->pdev, BIOS_CNTL, word & ~1);
pci_dev_put(window->pdev);
/* Free all of the mtd devices */ /* Free all of the mtd devices */
list_for_each_entry_safe(map, scratch, &window->maps, list) { list_for_each_entry_safe(map, scratch, &window->maps, list) {
...@@ -355,7 +356,7 @@ static int __init init_ichxrom(void) ...@@ -355,7 +356,7 @@ static int __init init_ichxrom(void)
pdev = NULL; pdev = NULL;
for (id = ichxrom_pci_tbl; id->vendor; id++) { for (id = ichxrom_pci_tbl; id->vendor; id++) {
pdev = pci_find_device(id->vendor, id->device, NULL); pdev = pci_get_device(id->vendor, id->device, NULL);
if (pdev) { if (pdev) {
break; break;
} }
......
...@@ -61,14 +61,17 @@ static int __init init_l440gx(void) ...@@ -61,14 +61,17 @@ static int __init init_l440gx(void)
struct resource *pm_iobase; struct resource *pm_iobase;
__u16 word; __u16 word;
dev = pci_find_device(PCI_VENDOR_ID_INTEL, dev = pci_get_device(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_82371AB_0, NULL); PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL, pm_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_82371AB_3, NULL); PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
pci_dev_put(dev);
if (!dev || !pm_dev) { if (!dev || !pm_dev) {
printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n"); printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
pci_dev_put(pm_dev);
return -ENODEV; return -ENODEV;
} }
...@@ -76,6 +79,7 @@ static int __init init_l440gx(void) ...@@ -76,6 +79,7 @@ static int __init init_l440gx(void)
if (!l440gx_map.virt) { if (!l440gx_map.virt) {
printk(KERN_WARNING "Failed to ioremap L440GX flash region\n"); printk(KERN_WARNING "Failed to ioremap L440GX flash region\n");
pci_dev_put(pm_dev);
return -ENOMEM; return -ENOMEM;
} }
simple_map_init(&l440gx_map); simple_map_init(&l440gx_map);
...@@ -99,8 +103,12 @@ static int __init init_l440gx(void) ...@@ -99,8 +103,12 @@ static int __init init_l440gx(void)
pm_iobase->start += iobase & ~1; pm_iobase->start += iobase & ~1;
pm_iobase->end += iobase & ~1; pm_iobase->end += iobase & ~1;
pci_dev_put(pm_dev);
/* Allocate the resource region */ /* Allocate the resource region */
if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) { if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) {
pci_dev_put(dev);
pci_dev_put(pm_dev);
printk(KERN_WARNING "Could not allocate pm iobase resource\n"); printk(KERN_WARNING "Could not allocate pm iobase resource\n");
iounmap(l440gx_map.virt); iounmap(l440gx_map.virt);
return -ENXIO; return -ENXIO;
......
...@@ -87,19 +87,23 @@ static int __init init_scx200_docflash(void) ...@@ -87,19 +87,23 @@ static int __init init_scx200_docflash(void)
printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n"); printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
if ((bridge = pci_find_device(PCI_VENDOR_ID_NS, if ((bridge = pci_get_device(PCI_VENDOR_ID_NS,
PCI_DEVICE_ID_NS_SCx200_BRIDGE, PCI_DEVICE_ID_NS_SCx200_BRIDGE,
NULL)) == NULL) NULL)) == NULL)
return -ENODEV; return -ENODEV;
/* check that we have found the configuration block */ /* check that we have found the configuration block */
if (!scx200_cb_present()) if (!scx200_cb_present()) {
pci_dev_put(bridge);
return -ENODEV; return -ENODEV;
}
if (probe) { if (probe) {
/* Try to use the present flash mapping if any */ /* Try to use the present flash mapping if any */
pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base); pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base);
pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl); pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl);
pci_dev_put(bridge);
pmr = inl(scx200_cb_base + SCx200_PMR); pmr = inl(scx200_cb_base + SCx200_PMR);
if (base == 0 if (base == 0
...@@ -127,6 +131,7 @@ static int __init init_scx200_docflash(void) ...@@ -127,6 +131,7 @@ static int __init init_scx200_docflash(void)
return -ENOMEM; return -ENOMEM;
} }
} else { } else {
pci_dev_put(bridge);
for (u = size; u > 1; u >>= 1) for (u = size; u > 1; u >>= 1)
; ;
if (u != 1) { if (u != 1) {
......
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