staging: comedi_pci: make comedi_pci_disable() safe to call
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 13 Mar 2013 17:35:51 +0000 (10:35 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 Mar 2013 20:42:49 +0000 (13:42 -0700)
Currently all the comedi PCI drivers need to do some checking in
their (*detach) before calling comedi_pci_disable() in order to
make sure the PCI device has actually be enabled.

Change the parameter passed to comedi_pci_disable() from a struct
pci_dev pointer to a comedi_device pointer and have comedi_pci_disable()
handle all the checking.

For most comedi PCI drivers this also allows removing the local
variable holding the pointer to the pci_dev. For some of the drivers
comedi_pci_disable can now be used directly as the (*detach) function.

The National Instruments drivers that use the mite module currently
enable/disable the PCI device in the mite module. For those drivers
move the call to comedi_pci_disable into the driver and make sure
dev->iobase is set to a non-zero value.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
53 files changed:
drivers/staging/comedi/comedi_pci.c
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers/8255_pci.c
drivers/staging/comedi/drivers/addi-data/addi_common.c
drivers/staging/comedi/drivers/addi_apci_1032.c
drivers/staging/comedi/drivers/addi_apci_1516.c
drivers/staging/comedi/drivers/addi_apci_16xx.c
drivers/staging/comedi/drivers/addi_apci_1710.c
drivers/staging/comedi/drivers/addi_apci_2032.c
drivers/staging/comedi/drivers/addi_apci_2200.c
drivers/staging/comedi/drivers/addi_apci_3120.c
drivers/staging/comedi/drivers/addi_apci_3501.c
drivers/staging/comedi/drivers/adl_pci6208.c
drivers/staging/comedi/drivers/adl_pci7x3x.c
drivers/staging/comedi/drivers/adl_pci8164.c
drivers/staging/comedi/drivers/adl_pci9111.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/adv_pci1723.c
drivers/staging/comedi/drivers/adv_pci1724.c
drivers/staging/comedi/drivers/adv_pci_dio.c
drivers/staging/comedi/drivers/amplc_dio200.c
drivers/staging/comedi/drivers/amplc_pc236.c
drivers/staging/comedi/drivers/amplc_pc263.c
drivers/staging/comedi/drivers/amplc_pci224.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/cb_pcidas64.c
drivers/staging/comedi/drivers/cb_pcidda.c
drivers/staging/comedi/drivers/cb_pcimdas.c
drivers/staging/comedi/drivers/cb_pcimdda.c
drivers/staging/comedi/drivers/contec_pci_dio.c
drivers/staging/comedi/drivers/daqboard2000.c
drivers/staging/comedi/drivers/das08_pci.c
drivers/staging/comedi/drivers/dt3000.c
drivers/staging/comedi/drivers/dyna_pci10xx.c
drivers/staging/comedi/drivers/gsc_hpdi.c
drivers/staging/comedi/drivers/icp_multi.c
drivers/staging/comedi/drivers/jr3_pci.c
drivers/staging/comedi/drivers/ke_counter.c
drivers/staging/comedi/drivers/me4000.c
drivers/staging/comedi/drivers/me_daq.c
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/ni_6527.c
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_660x.c
drivers/staging/comedi/drivers/ni_670x.c
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_pcidio.c
drivers/staging/comedi/drivers/ni_pcimio.c
drivers/staging/comedi/drivers/rtd520.c
drivers/staging/comedi/drivers/s626.c
drivers/staging/comedi/drivers/skel.c

index bf5095601e0021658c227df2f7130352327bac10..bee012c1e6a248624b8b4727b24cdbaaaeb6a098 100644 (file)
@@ -57,14 +57,16 @@ EXPORT_SYMBOL_GPL(comedi_pci_enable);
 
 /**
  * comedi_pci_disable() - Release the regions and disable the PCI device.
- * @pcidev: pci_dev struct
- *
- * This must be matched with a previous successful call to comedi_pci_enable().
+ * @dev: comedi_device struct
  */
-void comedi_pci_disable(struct pci_dev *pcidev)
+void comedi_pci_disable(struct comedi_device *dev)
 {
-       pci_release_regions(pcidev);
-       pci_disable_device(pcidev);
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+       if (pcidev && dev->iobase) {
+               pci_release_regions(pcidev);
+               pci_disable_device(pcidev);
+       }
 }
 EXPORT_SYMBOL_GPL(comedi_pci_disable);
 
index b8e5d091fff881ca6a56d52be13d8ce79c218635..9846c2ecc916dd421b31002f074ec94761b427a6 100644 (file)
@@ -385,7 +385,7 @@ struct pci_driver;
 struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
 
 int comedi_pci_enable(struct pci_dev *, const char *);
-void comedi_pci_disable(struct pci_dev *);
+void comedi_pci_disable(struct comedi_device *);
 
 int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
                           unsigned long context);
@@ -426,7 +426,7 @@ static inline int comedi_pci_enable(struct pci_dev *dev, const char *name)
        return -ENOSYS;
 }
 
-static inline void comedi_pci_disable(struct pci_dev *dev)
+static inline void comedi_pci_disable(struct comedi_device *dev)
 {
 }
 
index 7e25500cd996a9951c86823d1a0e5db875dcae73..a546dff61925fd6933fb2a274075e28777dfbd05 100644 (file)
@@ -247,7 +247,6 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
 
 static void pci_8255_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        const struct pci_8255_boardinfo *board = comedi_board(dev);
        struct pci_8255_private *devpriv = dev->private;
        struct comedi_subdevice *s;
@@ -261,12 +260,9 @@ static void pci_8255_detach(struct comedi_device *dev)
                        subdev_8255_cleanup(dev, s);
                }
        }
-       if (pcidev) {
-               if (devpriv->mmio_base)
-                       iounmap(devpriv->mmio_base);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       if (devpriv->mmio_base)
+               iounmap(devpriv->mmio_base);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver pci_8255_driver = {
index 3140880948e1b1e0d49d623273cd9755bef024f4..704a56eec6b75e01b453f9911f21d74de6683389 100644 (file)
@@ -317,7 +317,6 @@ static int addi_auto_attach(struct comedi_device *dev,
 
 static void i_ADDI_Detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct addi_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -328,8 +327,5 @@ static void i_ADDI_Detach(struct comedi_device *dev)
                if (devpriv->dw_AiBase)
                        iounmap(devpriv->dw_AiBase);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
index fdd053c61a63b1b83f827b6e761bc06cb2049a10..4da6e8b14dc17b1f77dcb3645b310504dc327a16 100644 (file)
@@ -353,16 +353,11 @@ static int apci1032_auto_attach(struct comedi_device *dev,
 
 static void apci1032_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci1032_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1032_driver = {
index 0319315ba9bd70488a5943d474ea8ab233a16caa..a7e449db46936fcf1c0ca320a8af7bbbe7cdd3e4 100644 (file)
@@ -201,14 +201,11 @@ static int apci1516_auto_attach(struct comedi_device *dev,
 
 static void apci1516_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci1516_reset(dev);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[2]);
-       if (dev->iobase)
-               comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1516_driver = {
index 8aca57f8590a6f7f097a4348448fc9fba4a1b14a..e2f9357d4c35f42c54a167d850269c308bab9ac7 100644 (file)
@@ -184,21 +184,11 @@ static int apci16xx_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void apci16xx_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver apci16xx_driver = {
        .driver_name    = "addi_apci_16xx",
        .module         = THIS_MODULE,
        .auto_attach    = apci16xx_auto_attach,
-       .detach         = apci16xx_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int apci16xx_pci_probe(struct pci_dev *dev,
index f654eb03473a20a2e020a9e2867ed5ad48b954c3..05e1b9c391e68c86bd7de5000baa013711451346 100644 (file)
@@ -73,16 +73,11 @@ static int apci1710_auto_attach(struct comedi_device *dev,
 
 static void apci1710_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                i_APCI1710_Reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1710_driver = {
index 4a33b3502f401ef0b09d816d2d731129556dd8d6..6e4ee0ae67aa03e52afd677e119218e9b20cc59d 100644 (file)
@@ -350,8 +350,6 @@ static int apci2032_auto_attach(struct comedi_device *dev,
 
 static void apci2032_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci2032_reset(dev);
        if (dev->irq)
@@ -360,10 +358,7 @@ static void apci2032_detach(struct comedi_device *dev)
                kfree(dev->read_subdev->private);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[1]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci2032_driver = {
index 48afa2316497edc88682ebfec4fdd75e2e72e1e1..aea0abb1a0af8bdf15ff8a8140f859009f7d0a64 100644 (file)
@@ -130,16 +130,11 @@ static int apci2200_auto_attach(struct comedi_device *dev,
 
 static void apci2200_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci2200_reset(dev);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[2]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci2200_driver = {
index 07bcb388fc5f32dd4ce139b3554e89caddb22615..056153157e51223ccb5230d8f2b2e85b3b7c6a4c 100644 (file)
@@ -203,7 +203,6 @@ static int apci3120_auto_attach(struct comedi_device *dev,
 
 static void apci3120_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct addi_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -222,10 +221,7 @@ static void apci3120_detach(struct comedi_device *dev)
                                devpriv->ui_DmaBufferPages[1]);
                }
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci3120_driver = {
index ecd54ea6f8de0e353054e7ce6c299d077d10d344..8bd3d72df0a6ef816bcfb7aa500656195c65094a 100644 (file)
@@ -423,16 +423,11 @@ static int apci3501_auto_attach(struct comedi_device *dev,
 
 static void apci3501_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci3501_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci3501_driver = {
index 49f82f48bf0909db4aa75b07b0cf20aa4071d292..8939bbdaee5f0f7e4c8009e4f15cc3789e908f01 100644 (file)
@@ -233,21 +233,11 @@ static int pci6208_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void pci6208_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci6208_driver = {
        .driver_name    = "adl_pci6208",
        .module         = THIS_MODULE,
        .auto_attach    = pci6208_auto_attach,
-       .detach         = pci6208_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci6208_pci_probe(struct pci_dev *dev,
index 70f8c93ef7ad7444f662e5c104af51ae75348997..bd2e58415d77aa9316489d26c6887187b8012c24 100644 (file)
@@ -259,21 +259,11 @@ static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void adl_pci7x3x_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci7x3x_driver = {
        .driver_name    = "adl_pci7x3x",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci7x3x_auto_attach,
-       .detach         = adl_pci7x3x_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
index de5cac05288880302ca2d3e46c8479a2093120be..008f89aea4babf88b11960ce1d8de6a154d1ec7a 100644 (file)
@@ -136,21 +136,11 @@ static int adl_pci8164_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void adl_pci8164_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci8164_driver = {
        .driver_name    = "adl_pci8164",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci8164_auto_attach,
-       .detach         = adl_pci8164_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci8164_pci_probe(struct pci_dev *dev,
index 8680cf18b7def34c749c4060143dece72a58dddf..ee45ee8c03c4a43a8585150bfcd5740e06dec86e 100644 (file)
@@ -939,16 +939,11 @@ static int pci9111_auto_attach(struct comedi_device *dev,
 
 static void pci9111_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                pci9111_reset(dev);
        if (dev->irq != 0)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adl_pci9111_driver = {
index a0277a83115d07879dcf99dca0cd6445abf77d33..2bf00e83454068f3256fe703b24d6f06fe1b6278 100644 (file)
@@ -2202,12 +2202,9 @@ static void pci9118_detach(struct comedi_device *dev)
                        free_pages((unsigned long)devpriv->dmabuf_virt[1],
                                   devpriv->dmabuf_pages[1]);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver adl_pci9118_driver = {
index 2f6c2d72986da14b6c010617ec32610f24461e5d..af302fe3f5cb54ca4ceba34defcff0a7b2613149 100644 (file)
@@ -1372,16 +1372,11 @@ static int pci1710_auto_attach(struct comedi_device *dev,
 
 static void pci1710_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                pci1710_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci1710_driver = {
index bd95b1d4338a392f2d1088a03d96b295b75df796..25f4cba5a75b69bbfe5293a976ced67078da6d3d 100644 (file)
@@ -306,14 +306,9 @@ static int pci1723_auto_attach(struct comedi_device *dev,
 
 static void pci1723_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase) {
-                       pci1723_reset(dev);
-                       comedi_pci_disable(pcidev);
-               }
-       }
+       if (dev->iobase)
+               pci1723_reset(dev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci1723_driver = {
index f448e4db4d950a14a23f5cac57346c02cb5e6a93..c799308adfb40f1c7c3d8d40c2c302f3d0fff3c4 100644 (file)
@@ -377,21 +377,11 @@ static int adv_pci1724_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void adv_pci1724_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev && dev->iobase) {
-               comedi_pci_disable(pcidev);
-               dev_info(dev->class_dev, "detached\n");
-       }
-}
-
 static struct comedi_driver adv_pci1724_driver = {
        .driver_name = "adv_pci1724",
        .module = THIS_MODULE,
        .auto_attach = adv_pci1724_auto_attach,
-       .detach = adv_pci1724_detach,
+       .detach = comedi_pci_disable,
 };
 
 static int adv_pci1724_pci_probe(struct pci_dev *dev,
index 52b6d0264d3489f28fb99762dead0621f0a473d8..79f72d6d7de1381f556f5934738cc68903ae406c 100644 (file)
@@ -1165,7 +1165,6 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
 static void pci_dio_detach(struct comedi_device *dev)
 {
        struct pci_dio_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct comedi_subdevice *s;
        int i;
 
@@ -1181,10 +1180,7 @@ static void pci_dio_detach(struct comedi_device *dev)
                        s->private = NULL;
                }
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci_dio_driver = {
index 82f80d563fbe308fa94a541f39c7c795b18d793c..d13a6dddcd09165bd2cdeb6287727d1a2d0b6362 100644 (file)
@@ -2029,14 +2029,9 @@ static void dio200_detach(struct comedi_device *dev)
                        release_region(devpriv->io.u.iobase,
                                       thisboard->mainsize);
        } else if (is_pci_board(thisboard)) {
-               struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (devpriv->io.regtype != no_regtype) {
-                               if (devpriv->io.regtype == mmio_regtype)
-                                       iounmap(devpriv->io.u.membase);
-                               comedi_pci_disable(pcidev);
-                       }
-               }
+               if (devpriv->io.regtype == mmio_regtype)
+                       iounmap(devpriv->io.u.membase);
+               comedi_pci_disable(dev);
        }
 }
 
index b6bba4d15a5ab5533ab60fb153a7a0fd52186710..45168488503d9691d59fa8adae93a4101eb2e1ee 100644 (file)
@@ -576,11 +576,9 @@ static void pc236_detach(struct comedi_device *dev)
                        release_region(dev->iobase, PC236_IO_SIZE);
        } else if (is_pci_board(thisboard)) {
                struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (dev->iobase)
-                               comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
+               if (pcidev)
                        pci_dev_put(pcidev);
-               }
        }
 }
 
index e61d55679a77991004d27176440192392ae4f1e3..d825414994b8f158c808a0277d74695d47d4457c 100644 (file)
@@ -335,11 +335,9 @@ static void pc263_detach(struct comedi_device *dev)
                        release_region(dev->iobase, PC263_IO_SIZE);
        } else if (is_pci_board(thisboard)) {
                struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (dev->iobase)
-                               comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
+               if (pcidev)
                        pci_dev_put(pcidev);
-               }
        }
 }
 
index 4a56468cb7baf3256bf04d4ed96a06fa4e4262de..3d5c1332eb34847bbc403cf025e2ec8dfc8eb905 100644 (file)
@@ -1488,11 +1488,9 @@ static void pci224_detach(struct comedi_device *dev)
                kfree(devpriv->ao_scan_vals);
                kfree(devpriv->ao_scan_order);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver amplc_pci224_driver = {
index 70074b5121305bb6c24cbdc82e30616582055752..1bfe893b4cb27930e71a540c855edbc24f358d43 100644 (file)
@@ -2840,11 +2840,9 @@ static void pci230_detach(struct comedi_device *dev)
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver amplc_pci230_driver = {
index 1f9316996951e203f26165fac36c906feeca85d1..04aa8d948a8b1c7b124099536733efb155f33e1a 100644 (file)
@@ -1458,6 +1458,7 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
        ret = comedi_pci_enable(pcidev, dev->board_name);
        if (ret)
                return ret;
+       dev->iobase = 1;
 
        devpriv->s5933_config = pci_resource_start(pcidev, 0);
        devpriv->control_status = pci_resource_start(pcidev, 1);
@@ -1599,7 +1600,6 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
 static void cb_pcidas_detach(struct comedi_device *dev)
 {
        struct cb_pcidas_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (devpriv) {
                if (devpriv->s5933_config) {
@@ -1611,10 +1611,7 @@ static void cb_pcidas_detach(struct comedi_device *dev)
                free_irq(dev->irq, dev);
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
-       if (pcidev) {
-               if (devpriv->s5933_config)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidas_driver = {
index e61cf71d46efdd49b62a65efe537c9fdf6e057a8..15a97212b15849a5b8288ad3c8e252640a2b53e3 100644 (file)
@@ -4194,10 +4194,7 @@ static void detach(struct comedi_device *dev)
        }
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[4]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidas64_driver = {
index 54cdb2728a81210539f6ac8e4dde9edc15edf0eb..aff16171ca938833ab5e5de9d3136d2fbf5b9ddd 100644 (file)
@@ -399,16 +399,11 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
 
 static void cb_pcidda_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->subdevices) {
                subdev_8255_cleanup(dev, &dev->subdevices[1]);
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidda_driver = {
index 7d456ad2aad42e2218c05efb7680edd0d8c211b3..8a8677f2525ebea3bce8ab5ba7fee5fca8c3ec73 100644 (file)
@@ -277,14 +277,9 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
 
 static void cb_pcimdas_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcimdas_driver = {
index 5db4f4ada4631b4980b22ca8a53abfa57f764709..7b8adec5e7b92105866c1a09292729120005e34a 100644 (file)
@@ -201,14 +201,9 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev,
 
 static void cb_pcimdda_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[1]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcimdda_driver = {
index d6597445aae896f192b9958452e16f058da10a95..b8c56a60cda972017f19f987ec0706534a775a98 100644 (file)
@@ -109,21 +109,11 @@ static int contec_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void contec_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver contec_pci_dio_driver = {
        .driver_name    = "contec_pci_dio",
        .module         = THIS_MODULE,
        .auto_attach    = contec_auto_attach,
-       .detach         = contec_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
index 42e13e30d5027de3c69d8b2e9fde440c41c1cf8e..077f9a5eb7c87f927e782e5d2700bdf3bd204570 100644 (file)
@@ -767,7 +767,6 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
 
 static void daqboard2000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct daqboard2000_private *devpriv = dev->private;
 
        if (dev->subdevices)
@@ -780,11 +779,7 @@ static void daqboard2000_detach(struct comedi_device *dev)
                if (devpriv->plx)
                        iounmap(devpriv->plx);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-               pci_dev_put(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver daqboard2000_driver = {
index a56cee7f86ddbae6875ada48b711c6665cbcad02..c64fb2775b8cded9c4e89ae420c1b8f29d313ef2 100644 (file)
@@ -81,11 +81,8 @@ static int das08_pci_auto_attach(struct comedi_device *dev,
 
 static void das08_pci_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pdev = comedi_to_pci_dev(dev);
-
        das08_common_detach(dev);
-       if (dev->iobase)
-               comedi_pci_disable(pdev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver das08_pci_comedi_driver = {
index 5726d56346c8aed90dea31c140419e7ff06fe5f3..296c5205ac9f2f617de0933bc56ca87792953532 100644 (file)
@@ -814,7 +814,6 @@ static int dt3000_auto_attach(struct comedi_device *dev,
 
 static void dt3000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct dt3k_private *devpriv = dev->private;
 
        if (dev->irq)
@@ -823,10 +822,7 @@ static void dt3000_detach(struct comedi_device *dev)
                if (devpriv->io_addr)
                        iounmap(devpriv->io_addr);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver dt3000_driver = {
index 58ff129a833904b811477ee3157f2d5c9e92fae2..9f83dfbcf2956ddd547034363dbbda2d0f4310fa 100644 (file)
@@ -254,15 +254,11 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
 
 static void dyna_pci10xx_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct dyna_pci10xx_private *devpriv = dev->private;
 
        if (devpriv)
                mutex_destroy(&devpriv->mutex);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver dyna_pci10xx_driver = {
index a18d897606f8f48614d35ea5ccc6ff727246be8e..f0e92143ac8982780064caf211cab1fcbfae62eb 100644 (file)
@@ -596,9 +596,8 @@ static void hpdi_detach(struct comedi_device *dev)
                                            NUM_DMA_DESCRIPTORS,
                                            devpriv->dma_desc,
                                            devpriv->dma_desc_phys_addr);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
        }
+       comedi_pci_disable(dev);
 }
 
 static int dio_config_block_size(struct comedi_device *dev, unsigned int *data)
index 9a466879e493e1bae609d72f506d12e06db63157..65265c3ce3ff69a4c162c51b152100261a69544e 100644 (file)
@@ -594,7 +594,6 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
 
 static void icp_multi_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct icp_multi_private *devpriv = dev->private;
 
        if (devpriv)
@@ -604,10 +603,7 @@ static void icp_multi_detach(struct comedi_device *dev)
                free_irq(dev->irq, dev);
        if (devpriv && devpriv->io_addr)
                iounmap(devpriv->io_addr);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver icp_multi_driver = {
index aea940121c58aa622a25e04c96d77590530b3eb5..f1ae9a814d8fd1fb4109c2b0aae99595372a9362 100644 (file)
@@ -816,7 +816,6 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
 static void jr3_pci_detach(struct comedi_device *dev)
 {
        int i;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct jr3_pci_dev_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -828,9 +827,8 @@ static void jr3_pci_detach(struct comedi_device *dev)
                }
                if (devpriv->iobase)
                        iounmap(devpriv->iobase);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver jr3_pci_driver = {
index ac40e355dff2d5f69851ac35cd39a5b390c569c2..74318f204e25b8801b3e28d6a292c3fcf5bdd0b2 100644 (file)
@@ -131,21 +131,11 @@ static int cnt_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void cnt_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver ke_counter_driver = {
        .driver_name    = "ke_counter",
        .module         = THIS_MODULE,
        .auto_attach    = cnt_auto_attach,
-       .detach         = cnt_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int ke_counter_pci_probe(struct pci_dev *dev,
index 141a3f7bbf15bf065aa8f3d625c24f23b87eb8ea..6bc1347eaf68271f614ed08465ef6a4602d8b38c 100644 (file)
@@ -1697,16 +1697,11 @@ static int me4000_auto_attach(struct comedi_device *dev,
 
 static void me4000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase) {
-                       me4000_reset(dev);
-                       comedi_pci_disable(pcidev);
-               }
-       }
+       if (dev->iobase)
+               me4000_reset(dev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver me4000_driver = {
index 55d66d0295e0d8cda97fc21e10313abf5b4e0967..8951a673c2d1b5cd66409897e8acc838928dfe24 100644 (file)
@@ -580,7 +580,6 @@ static int me_auto_attach(struct comedi_device *dev,
 
 static void me_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct me_private_data *dev_private = dev->private;
 
        if (dev_private) {
@@ -591,10 +590,7 @@ static void me_detach(struct comedi_device *dev)
                if (dev_private->plx_regbase)
                        iounmap(dev_private->plx_regbase);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver me_daq_driver = {
index be2c15f84614400fc1b43cf552bbecdbf06c683f..5a3b14fb4de19520afe6f3d5f282be19942a1556 100644 (file)
@@ -208,10 +208,8 @@ void mite_unsetup(struct mite_struct *mite)
                iounmap(mite->daq_io_addr);
                mite->daq_io_addr = NULL;
        }
-       if (mite->mite_phys_addr) {
-               comedi_pci_disable(mite->pcidev);
+       if (mite->mite_phys_addr)
                mite->mite_phys_addr = 0;
-       }
 }
 EXPORT_SYMBOL(mite_unsetup);
 
index 514d5db92028bfc61bf7934156b7e238e9cec6ba..194eac63dd3e75ad30f9b626628518990fa3b1d4 100644 (file)
@@ -350,6 +350,7 @@ static int ni6527_auto_attach(struct comedi_device *dev,
                dev_err(dev->class_dev, "error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        dev_info(dev->class_dev, "board: %s, ID=0x%02x\n", dev->board_name,
                 readb(devpriv->mite->daq_io_addr + ID_Register));
@@ -419,6 +420,7 @@ static void ni6527_detach(struct comedi_device *dev)
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni6527_driver = {
index 74a1e65010cfaff3296ab6ce0e59bd30efd07147..b882a5f5b035e684dc5456232f7f96448d4241de 100644 (file)
@@ -614,6 +614,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                dev_warn(dev->class_dev, "error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        dev->irq = mite_irq(devpriv->mite);
        dev_info(dev->class_dev, "board: %s, ID=0x%02x", dev->board_name,
@@ -748,6 +749,7 @@ static void ni_65xx_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_65xx_driver = {
index d2e061a195d0d32776f9810cde39c0d3bcaa081e..cc82106af7f02bf578f3951989333b9b94aba0c3 100644 (file)
@@ -1188,6 +1188,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
                dev_warn(dev->class_dev, "error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        ret = ni_660x_alloc_mite_rings(dev);
        if (ret < 0)
@@ -1302,6 +1303,7 @@ static void ni_660x_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_660x_driver = {
index 0e7b957afbe4d029b2baf623670303b6a3d0a014..5ec6f829a924aa865bf9b0aa082b079d1051bb93 100644 (file)
@@ -222,6 +222,7 @@ static int ni_670x_auto_attach(struct comedi_device *dev,
                dev_warn(dev->class_dev, "error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        ret = comedi_alloc_subdevices(dev, 2);
        if (ret)
@@ -286,6 +287,7 @@ static void ni_670x_detach(struct comedi_device *dev)
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_670x_driver = {
index d386c3e2b976f2fc585a6a498340e14d9d8f3599..9082eca09499356e572a22c0eed73752bbc614bb 100644 (file)
@@ -722,6 +722,7 @@ static int labpc_auto_attach(struct comedi_device *dev,
        ret = mite_setup(devpriv->mite);
        if (ret < 0)
                return ret;
+       dev->iobase = 1;
        iobase = (unsigned long)devpriv->mite->daq_io_addr;
        irq = mite_irq(devpriv->mite);
        return labpc_common_attach(dev, iobase, irq, 0);
@@ -800,6 +801,7 @@ void labpc_common_detach(struct comedi_device *dev)
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
        }
+       comedi_pci_disable(dev);
 #endif
 };
 EXPORT_SYMBOL_GPL(labpc_common_detach);
index 50e025b07780caa8f6c33455a64f03a85494859e..8f743751507b476c93797c018447b1074c2f26b9 100644 (file)
@@ -1128,6 +1128,7 @@ static int nidio_auto_attach(struct comedi_device *dev,
                dev_warn(dev->class_dev, "error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        devpriv->di_mite_ring = mite_alloc_ring(devpriv->mite);
        if (devpriv->di_mite_ring == NULL)
@@ -1202,6 +1203,7 @@ static void nidio_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_pcidio_driver = {
index 4d1a431edee039faead14605f622a938604ef8c0..0f18f8dda5fb84c6d73e9d0e2290abd350401f33 100644 (file)
@@ -1470,6 +1470,7 @@ static void pcimio_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static int pcimio_auto_attach(struct comedi_device *dev,
@@ -1513,6 +1514,7 @@ static int pcimio_auto_attach(struct comedi_device *dev,
                pr_warn("error setting up mite\n");
                return ret;
        }
+       dev->iobase = 1;
 
        devpriv->ai_mite_ring = mite_alloc_ring(devpriv->mite);
        if (devpriv->ai_mite_ring == NULL)
index 5ee38b149b512427543002f5904eabd3a45b02bc..5b0676817726364ee40fff61d8267fa91b29f371 100644 (file)
@@ -1373,7 +1373,6 @@ static int rtd_auto_attach(struct comedi_device *dev,
 static void rtd_detach(struct comedi_device *dev)
 {
        struct rtdPrivate *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (devpriv) {
                /* Shut down any board ops by resetting it */
@@ -1392,10 +1391,7 @@ static void rtd_detach(struct comedi_device *dev)
                if (devpriv->lcfg)
                        iounmap(devpriv->lcfg);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver rtd520_driver = {
index 4fec6d6a04abbb96fb3031e1b240f386e50c3918..92338791f4a255bc743c62c8ab6eba496a9322f7 100644 (file)
@@ -2790,7 +2790,6 @@ static int s626_auto_attach(struct comedi_device *dev,
 
 static void s626_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct s626_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -2818,10 +2817,7 @@ static void s626_detach(struct comedi_device *dev)
                if (devpriv->base_addr)
                        iounmap(devpriv->base_addr);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver s626_driver = {
index 1737c2a06ae37585d432653bc2c324d8bb526e87..f5d708c3aa5bf96ef745d5734f1d2a3da692686f 100644 (file)
@@ -606,7 +606,6 @@ static void skel_detach(struct comedi_device *dev)
 {
        const struct skel_board *thisboard = comedi_board(dev);
        struct skel_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (!thisboard || !devpriv)
                return;
@@ -626,8 +625,7 @@ static void skel_detach(struct comedi_device *dev)
                 * If PCI device enabled by _auto_attach() (or _attach()),
                 * disable it here.
                 */
-               if (pcidev && dev->iobase)
-                       comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
        } else {
                /*
                 * ISA board