Skip to contentSkip to conversation

: Switch fdomain to the pci_get API

PATCH In review Alan Cox 2 participants 3 messages Oct 16, 2006 SCSI

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 : Switch fdomain to the pci_get API

Doesn't make the hardware hot pluggable but does ensure the driver won't crash when another device is hot-unplugged at the wrong moment. Soon I propose to deprecate pci_find_device() and some of its friends.

drivers/scsi/fdomain.c +21 -11
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.19-rc1-mm1/drivers/scsi/fdomain.c linux-2.6.19-rc1-mm1/drivers/scsi/fdomain.c
@@ -387,6 +387,7 @@
 static int               bios_major;
 static int               bios_minor;
 static int               PCI_bus;
+static struct pci_dev	*PCI_dev;
 static int               Quantum;	/* Quantum board variant */
 static int               interrupt_level;
 static volatile int      in_command;
@@ -816,9 +817,10 @@
 	   PCI_DEVICE_ID_FD_36C70 );
 #endif 
 
-   if ((pdev = pci_find_device(PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70, pdev)) == NULL)
+   if ((pdev = pci_get_device(PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70, pdev)) == NULL)
 		return 0;
-   if (pci_enable_device(pdev)) return 0;
+   if (pci_enable_device(pdev))
+   	goto fail;
        
 #if DEBUG_DETECT
    printk( "scsi: <fdomain> TMC-3260 detect:"
@@ -833,9 +835,9 @@
 
    pci_base = pci_resource_start(pdev, 0);
    pci_irq = pdev->irq;
-
+   
    if (!request_region( pci_base, 0x10, "fdomain" ))
-	return 0;
+   	goto fail;
 
    /* Now we have the I/O base address and interrupt from the PCI
       configuration registers. */
@@ -852,17 +854,22 @@
    if (!fdomain_is_valid_port(pci_base)) {
       printk(KERN_ERR "scsi: <fdomain> PCI card detected, but driver not loaded (invalid port)\n" );
       release_region(pci_base, 0x10);
-      return 0;
+      goto fail;
    }
 
 				/* Fill in a few global variables.  Ugh. */
    bios_major = bios_minor = -1;
    PCI_bus    = 1;
+   PCI_dev    = pdev;
    Quantum    = 0;
    bios_base  = 0;
    
    return 1;
+fail:
+   pci_dev_put(pdev);
+   return 0;
 }
+
 #endif
 
 struct Scsi_Host *__fdomain_16x0_detect(struct scsi_host_template *tpnt )
@@ -913,8 +920,7 @@
       if (setup_called) {
 	 printk(KERN_ERR "scsi: <fdomain> Bad LILO/INSMOD parameters?\n");
       }
-      release_region(port_base, 0x10);
-      return NULL;
+      goto fail;
    }
 
    if (this_id) {
@@ -946,8 +952,7 @@
    /* Log IRQ with kernel */   
    if (!interrupt_level) {
       printk(KERN_ERR "scsi: <fdomain> Card Detected, but driver not loaded (no IRQ)\n" );
-      release_region(port_base, 0x10);
-      return NULL;
+      goto fail;
    } else {
       /* Register the IRQ with the kernel */
 
@@ -968,11 +973,14 @@
 	    printk(KERN_ERR "                Send mail to [email protected]\n" );
 	 }
 	 printk(KERN_ERR "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
-         release_region(port_base, 0x10);
-	 return NULL;
+	 goto fail;
       }
    }
    return shpnt;
+fail:
+   pci_dev_put(pdev);
+   release_region(port_base, 0x10);
+   return NULL;
 }
 
 static int fdomain_16x0_detect(struct scsi_host_template *tpnt)
@@ -1718,6 +1726,8 @@
 		free_irq(shpnt->irq, shpnt);
 	if (shpnt->io_port && shpnt->n_io_port)
 		release_region(shpnt->io_port, shpnt->n_io_port);
+	if (PCI_bus)
+		pci_dev_put(PCI_dev);
 	return 0;
 }
 
#1 lore raw

drivers/scsi/fdomain.c line 1730

Quoted 2 lines · Alan Cox
drivers/scsi/fdomain.c +2 -0
+	if (PCI_bus)
+		pci_dev_put(PCI_dev);

shirley 'if (PCI_dev)'?

author
#2 lore raw

Ar Llu, 2006-10-16 am 10:20 -0600, ysgrifennodd Matthew Wilcox:

Quoted 5 lines · Alan Cox

drivers/scsi/fdomain.c line 1730

Quoted 2 lines
drivers/scsi/fdomain.c +2 -0
+	if (PCI_bus)
+		pci_dev_put(PCI_dev);

shirley 'if (PCI_dev)'?

No

The PCI_bus flag tells us that the hardware found and uses a PCI device, which means PCI_dev holds a valid value (or NULL) which can and should be passed to pci_dev_put.

Don't blame me I didn't write the driver ;)

Alan