staging: comedi: comedi_pci: introduce comedi_pci_detach()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 26 Aug 2014 00:55:48 +0000 (17:55 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:24:54 +0000 (13:24 -0700)
Introduce a generic (*detach) function for comedi PCI drivers to handle
the boilerplate code needed to detach a PCI driver.

This function works similar to comedi_legacy_detach() where it will:

  * free the dev->irq if it has been requested
  * iounmap the dev->mmio addres if it has been ioremap'ed

The helper then calls comedi_pci_disable() to release the regions and
disable the PCI device.

Use the new helper directly for the (*detach) in the following cases:

  * where comedi_pci_disable() is used directly for the (*detach)
  * where the detach function is just boilerplate

Use the new helper in the (*detach) of the simpler PCI drivers. Call
the helper after disabling interrupts (reset) and before any additional
cleanup (kfree) to avoid any race conditions with the interrupt handler.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46 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_1564.c
drivers/staging/comedi/drivers/addi_apci_16xx.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/addi_apci_3xxx.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_pci.c
drivers/staging/comedi/drivers/amplc_pci224.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/amplc_pci236.c
drivers/staging/comedi/drivers/amplc_pci263.c
drivers/staging/comedi/drivers/cb_pcidas.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/icp_multi.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/mf6x4.c
drivers/staging/comedi/drivers/ni_6527.c
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_670x.c
drivers/staging/comedi/drivers/ni_labpc_pci.c
drivers/staging/comedi/drivers/skel.c

index abbc0e4f5c51288b9eae4ec0d32b4e2c06d9579a..aa0795a2660e15729cd67bc1ba8ec67083a06f87 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <linux/pci.h>
+#include <linux/interrupt.h>
 
 #include "comedidev.h"
 
@@ -72,6 +73,29 @@ void comedi_pci_disable(struct comedi_device *dev)
 }
 EXPORT_SYMBOL_GPL(comedi_pci_disable);
 
+/**
+ * comedi_pci_detach() - A generic (*detach) function for PCI drivers.
+ * @dev: comedi_device struct
+ */
+void comedi_pci_detach(struct comedi_device *dev)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+       if (!pcidev || !dev->ioenabled)
+               return;
+
+       if (dev->irq) {
+               free_irq(dev->irq, dev);
+               dev->irq = 0;
+       }
+       if (dev->mmio) {
+               iounmap(dev->mmio);
+               dev->mmio = NULL;
+       }
+       comedi_pci_disable(dev);
+}
+EXPORT_SYMBOL_GPL(comedi_pci_detach);
+
 /**
  * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
  * @pcidev: pci_dev struct
index a883862b1feb9958de0e81c9f63e047725bf0d38..bda53047d256404535f736cd2386c1efcced2ce3 100644 (file)
@@ -509,6 +509,7 @@ struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
 
 int comedi_pci_enable(struct comedi_device *);
 void comedi_pci_disable(struct comedi_device *);
+void comedi_pci_detach(struct comedi_device *);
 
 int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
                           unsigned long context);
@@ -553,6 +554,10 @@ static inline void comedi_pci_disable(struct comedi_device *dev)
 {
 }
 
+static inline void comedi_pci_detach(struct comedi_device *dev)
+{
+}
+
 #endif /* CONFIG_COMEDI_PCI_DRIVERS */
 
 #ifdef CONFIG_COMEDI_PCMCIA_DRIVERS
index 8bcb1e0e6a71d159d7045cb36ac0c5640907dfef..8b958982885535fe879776f483ab0a0fbed3e9c9 100644 (file)
@@ -246,18 +246,11 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void pci_8255_detach(struct comedi_device *dev)
-{
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver pci_8255_driver = {
        .driver_name    = "8255_pci",
        .module         = THIS_MODULE,
        .auto_attach    = pci_8255_auto_attach,
-       .detach         = pci_8255_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static int pci_8255_pci_probe(struct pci_dev *dev,
index de5843ab01aeaec011289a7c30fc4ca8f2b7554e..025b4513f0af6ea7aa67805e7f6a6a1c022d0ebc 100644 (file)
@@ -268,13 +268,7 @@ static int addi_auto_attach(struct comedi_device *dev,
 
 static void i_ADDI_Detach(struct comedi_device *dev)
 {
-       struct addi_private *devpriv = dev->private;
-
-       if (devpriv) {
-               if (dev->iobase)
-                       i_ADDI_Reset(dev);
-               if (dev->irq)
-                       free_irq(dev->irq, dev);
-       }
-       comedi_pci_disable(dev);
+       if (dev->iobase)
+               i_ADDI_Reset(dev);
+       comedi_pci_detach(dev);
 }
index 44080f6c887f4a79d09de379eef81fede5680d80..840cb289507a77220e045fba50ba4e637bce5ffa 100644 (file)
@@ -343,9 +343,7 @@ static void apci1032_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci1032_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci1032_driver = {
index e9c5291c77cd439d1a6733c2b6b7a0604a6dd671..5cd396858aa62a14a0a38580d5fd25577321cb42 100644 (file)
@@ -190,7 +190,7 @@ static void apci1516_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci1516_reset(dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci1516_driver = {
index 0940c0da96d5b2789eac9beae2730dfc5c24efac..fb6a78153529fdf4495ca2855d237453701f565f 100644 (file)
@@ -442,9 +442,7 @@ static void apci1564_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci1564_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci1564_driver = {
index 28df4b50b87adb1251cf6934a2c6ba7f15671381..4162e2dc2860ec6495cac3e70462f182a2eabe96 100644 (file)
@@ -159,7 +159,7 @@ static struct comedi_driver apci16xx_driver = {
        .driver_name    = "addi_apci_16xx",
        .module         = THIS_MODULE,
        .auto_attach    = apci16xx_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int apci16xx_pci_probe(struct pci_dev *dev,
index 6768d1dc200561a538abfd57644014ff096865b3..45ea4a4e451bb4a75a7a81bc2c71f5a6a848e857 100644 (file)
@@ -338,11 +338,9 @@ static void apci2032_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci2032_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
+       comedi_pci_detach(dev);
        if (dev->read_subdev)
                kfree(dev->read_subdev->private);
-       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci2032_driver = {
index e1a916546d18a3dbc67604c2fb5e7b6ce1299666..51ab1f937baec387dae046d7b4e5e9c18db376a3 100644 (file)
@@ -118,7 +118,7 @@ static void apci2200_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci2200_reset(dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci2200_driver = {
index 0b77f1012d473476a35b46bd1b89eb5e23b0e4b3..050c72493298e483f8d464d1c36eee92573dc0eb 100644 (file)
@@ -195,11 +195,10 @@ static void apci3120_detach(struct comedi_device *dev)
 {
        struct addi_private *devpriv = dev->private;
 
+       if (dev->iobase)
+               apci3120_reset(dev);
+       comedi_pci_detach(dev);
        if (devpriv) {
-               if (dev->iobase)
-                       apci3120_reset(dev);
-               if (dev->irq)
-                       free_irq(dev->irq, dev);
                if (devpriv->ul_DmaBufferVirtual[0]) {
                        free_pages((unsigned long)devpriv->
                                ul_DmaBufferVirtual[0],
@@ -211,7 +210,6 @@ static void apci3120_detach(struct comedi_device *dev)
                                devpriv->ui_DmaBufferPages[1]);
                }
        }
-       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci3120_driver = {
index 56781c15534317e8ce90c76e084c7c70b173dd47..010efa3fed6caba7d2e1ad3553de2f20e2bd514c 100644 (file)
@@ -417,9 +417,7 @@ static void apci3501_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci3501_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci3501_driver = {
index 1f59f1681831e3b75b42fd37137f1e1ca83c1747..57e6f889d73f1e89f5c9a32fc48b6d4b2b9c871b 100644 (file)
@@ -910,17 +910,9 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
 
 static void apci3xxx_detach(struct comedi_device *dev)
 {
-       struct apci3xxx_private *devpriv = dev->private;
-
-       if (devpriv) {
-               if (dev->iobase)
-                       apci3xxx_reset(dev);
-               if (dev->irq)
-                       free_irq(dev->irq, dev);
-               if (dev->mmio)
-                       iounmap(dev->mmio);
-       }
-       comedi_pci_disable(dev);
+       if (dev->iobase)
+               apci3xxx_reset(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver apci3xxx_driver = {
index 1e8b0905a8457442564659b1dbf3001645e306f4..0ad46fe492c99d5be6173650650765a84fed04f0 100644 (file)
@@ -208,7 +208,7 @@ static struct comedi_driver adl_pci6208_driver = {
        .driver_name    = "adl_pci6208",
        .module         = THIS_MODULE,
        .auto_attach    = pci6208_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int adl_pci6208_pci_probe(struct pci_dev *dev,
index 5e3cc77a8a0c07417c85d0bb6ed69b471c8f405b..fb8e5f58249663233955cd64b234b654b40fcdc4 100644 (file)
@@ -246,7 +246,7 @@ static struct comedi_driver adl_pci7x3x_driver = {
        .driver_name    = "adl_pci7x3x",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci7x3x_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
index 300df55a2802d21d6b0f3161498f7eba4fb90cb7..72bccb447a7410dd7eaf586b7778772d1e6f03d1 100644 (file)
@@ -135,7 +135,7 @@ static struct comedi_driver adl_pci8164_driver = {
        .driver_name    = "adl_pci8164",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci8164_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int adl_pci8164_pci_probe(struct pci_dev *dev,
index 9ba367e27e938573327dbb2bd95cbd616e0a8808..d18d8f21af2341898696f74dea8f2b7602182e37 100644 (file)
@@ -781,9 +781,7 @@ static void pci9111_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                pci9111_reset(dev);
-       if (dev->irq != 0)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver adl_pci9111_driver = {
index f30b84e1987bd469670ad26b1183dfedc5e8c384..6fc50b3735c0301c76c2cc314d79b45db48b11ad 100644 (file)
@@ -2033,11 +2033,10 @@ static void pci9118_detach(struct comedi_device *dev)
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct pci9118_private *devpriv = dev->private;
 
+       if (dev->iobase)
+               pci9118_reset(dev);
+       comedi_pci_detach(dev);
        if (devpriv) {
-               if (dev->iobase)
-                       pci9118_reset(dev);
-               if (dev->irq)
-                       free_irq(dev->irq, dev);
                if (devpriv->dmabuf_virt[0])
                        free_pages((unsigned long)devpriv->dmabuf_virt[0],
                                   devpriv->dmabuf_pages[0]);
@@ -2045,7 +2044,6 @@ static void pci9118_detach(struct comedi_device *dev)
                        free_pages((unsigned long)devpriv->dmabuf_virt[1],
                                   devpriv->dmabuf_pages[1]);
        }
-       comedi_pci_disable(dev);
        if (pcidev)
                pci_dev_put(pcidev);
 }
index e19ab958791b1c7afd4602c6a6a2f55a951212ae..3e37b0b6f37a4542a777d456793b9484f6b46d0e 100644 (file)
@@ -1250,9 +1250,7 @@ static void pci1710_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                pci1710_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver adv_pci1710_driver = {
index 1881df459dae6b6cd5936899cc0dac431ac08d3d..1610e2b406f3de779adb546248875f2d61dcd530 100644 (file)
@@ -286,7 +286,7 @@ static void pci1723_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                pci1723_reset(dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver adv_pci1723_driver = {
index bc3c34916768a838715a11c0ad373e28a5513512..2697758b1ed9d8e8fa068161b0e7403f82ca8939 100644 (file)
@@ -372,7 +372,7 @@ static struct comedi_driver adv_pci1724_driver = {
        .driver_name = "adv_pci1724",
        .module = THIS_MODULE,
        .auto_attach = adv_pci1724_auto_attach,
-       .detach = comedi_pci_disable,
+       .detach = comedi_pci_detach,
 };
 
 static int adv_pci1724_pci_probe(struct pci_dev *dev,
index f3e2268d4feecac539b0cd16c44cca2ad2fb335e..8aab4949a96c84c0aa0cc1fc41838dc451d0e2f8 100644 (file)
@@ -1170,7 +1170,7 @@ static void pci_dio_detach(struct comedi_device *dev)
                if (devpriv->valid)
                        pci_dio_reset(dev);
        }
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver adv_pci_dio_driver = {
index 423b6249d4f12750689c6106f62ca9d1b21947db..b83d1f5a8fb999395dbaa34789e3daeeddfe4079 100644 (file)
@@ -387,20 +387,11 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
        return amplc_dio200_common_attach(dev, pci_dev->irq, IRQF_SHARED);
 }
 
-static void dio200_pci_detach(struct comedi_device *dev)
-{
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver dio200_pci_comedi_driver = {
        .driver_name    = "amplc_dio200_pci",
        .module         = THIS_MODULE,
        .auto_attach    = dio200_pci_auto_attach,
-       .detach         = dio200_pci_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static const struct pci_device_id dio200_pci_table[] = {
index ba247741adaf0f9e2e75005298936188c7193851..b65cd484d61eaa3367e7e9021ba749c91ce15f9a 100644 (file)
@@ -1130,13 +1130,11 @@ static void pci224_detach(struct comedi_device *dev)
 {
        struct pci224_private *devpriv = dev->private;
 
-       if (dev->irq)
-               free_irq(dev->irq, dev);
+       comedi_pci_detach(dev);
        if (devpriv) {
                kfree(devpriv->ao_scan_vals);
                kfree(devpriv->ao_scan_order);
        }
-       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver amplc_pci224_driver = {
index 2fc499217377e14602f16f7af4d85ee1fd32da29..0da5a4a47961ce1657e88ee99a98555522c2105c 100644 (file)
@@ -2830,9 +2830,7 @@ static void pci230_detach(struct comedi_device *dev)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
        if (pcidev)
                pci_dev_put(pcidev);
 }
index 436aebaf76212702b9640fdf9f755efa0c02f789..ad1e93dd13a0132b88c2cf0be405236139d5e4f7 100644 (file)
@@ -119,18 +119,11 @@ static int pci236_auto_attach(struct comedi_device *dev,
                                         IRQF_SHARED);
 }
 
-static void pci236_detach(struct comedi_device *dev)
-{
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver amplc_pci236_driver = {
        .driver_name = "amplc_pci236",
        .module = THIS_MODULE,
        .auto_attach = pci236_auto_attach,
-       .detach = pci236_detach,
+       .detach = comedi_pci_detach,
 };
 
 static const struct pci_device_id pci236_pci_table[] = {
index 748a6b108f323cf7cbfd6981d311827a83a4d64e..2259bee98d48d1951192935ccf9f4e479dd9857f 100644 (file)
@@ -86,7 +86,7 @@ static struct comedi_driver amplc_pci263_driver = {
        .driver_name    = "amplc_pci263",
        .module         = THIS_MODULE,
        .auto_attach    = pci263_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static const struct pci_device_id pci263_pci_table[] = {
index b2be8f3251e13eaa58b91476d19eab19c8275b48..a0bb4c86904464117348ee3556f483659fe92a31 100644 (file)
@@ -1589,15 +1589,11 @@ static void cb_pcidas_detach(struct comedi_device *dev)
 {
        struct cb_pcidas_private *devpriv = dev->private;
 
-       if (devpriv) {
-               if (devpriv->s5933_config) {
-                       outl(INTCSR_INBOX_INTR_STATUS,
-                            devpriv->s5933_config + AMCC_OP_REG_INTCSR);
-               }
+       if (devpriv && devpriv->s5933_config) {
+               outl(INTCSR_INBOX_INTR_STATUS,
+                    devpriv->s5933_config + AMCC_OP_REG_INTCSR);
        }
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver cb_pcidas_driver = {
index 91ba90b5ceae869678ace1e1b9bf8f9e4de11c3b..01875d7c376f1e40687283f895948e8f4d0a657c 100644 (file)
@@ -398,7 +398,7 @@ static struct comedi_driver cb_pcidda_driver = {
        .driver_name    = "cb_pcidda",
        .module         = THIS_MODULE,
        .auto_attach    = cb_pcidda_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int cb_pcidda_pci_probe(struct pci_dev *dev,
index 1bbe769c30b546a83029dd4fed1db8eeb009cad3..fe4d2544f3dc2318b9fe005f7fe3c675b71b2dba 100644 (file)
@@ -236,18 +236,11 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void cb_pcimdas_detach(struct comedi_device *dev)
-{
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver cb_pcimdas_driver = {
        .driver_name    = "cb_pcimdas",
        .module         = THIS_MODULE,
        .auto_attach    = cb_pcimdas_auto_attach,
-       .detach         = cb_pcimdas_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static int cb_pcimdas_pci_probe(struct pci_dev *dev,
index 361213cdc58e0e1c3f69e539840f7da41dd7a992..03043e7b9b589109fd256674fa056f6f8e018c7a 100644 (file)
@@ -176,7 +176,7 @@ static struct comedi_driver cb_pcimdda_driver = {
        .driver_name    = "cb_pcimdda",
        .module         = THIS_MODULE,
        .auto_attach    = cb_pcimdda_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
index f066fb06dc1dfe72eb5887056c37ae56a7f7b2c8..205f9df345a212d9beafde891ce2c125617b863c 100644 (file)
@@ -97,7 +97,7 @@ static struct comedi_driver contec_pci_dio_driver = {
        .driver_name    = "contec_pci_dio",
        .module         = THIS_MODULE,
        .auto_attach    = contec_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
index dc299f6fa611f589556fe121c049a5647fee1687..e5b5a8133b340b736291ba6ad440ba84b9b9d573 100644 (file)
@@ -727,15 +727,9 @@ static void daqboard2000_detach(struct comedi_device *dev)
 {
        struct daqboard2000_private *devpriv = dev->private;
 
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (devpriv) {
-               if (dev->mmio)
-                       iounmap(dev->mmio);
-               if (devpriv->plx)
-                       iounmap(devpriv->plx);
-       }
-       comedi_pci_disable(dev);
+       if (devpriv && devpriv->plx)
+               iounmap(devpriv->plx);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver daqboard2000_driver = {
index 4ce3eb0a64cc15a8bf0399516b35249649f096cc..0987ce55494538514edf08bf9ff5728511d739b2 100644 (file)
@@ -77,7 +77,7 @@ static struct comedi_driver das08_pci_comedi_driver = {
        .driver_name    = "pci-das08",
        .module         = THIS_MODULE,
        .auto_attach    = das08_pci_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int das08_pci_probe(struct pci_dev *dev,
index bcbba09b083a03365ddd06f21588cb739ced2809..ab1fe4a4ac61114e9065a586df6040650b7a52ad 100644 (file)
@@ -735,20 +735,11 @@ static int dt3000_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void dt3000_detach(struct comedi_device *dev)
-{
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver dt3000_driver = {
        .driver_name    = "dt3000",
        .module         = THIS_MODULE,
        .auto_attach    = dt3000_auto_attach,
-       .detach         = dt3000_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static int dt3000_pci_probe(struct pci_dev *dev,
index e5593f8c7406d3c8e693b6456b87955c4b0ae1da..608aee0c3a15dfae3ba870f61ba398641fd5f9e5 100644 (file)
@@ -243,9 +243,9 @@ static void dyna_pci10xx_detach(struct comedi_device *dev)
 {
        struct dyna_pci10xx_private *devpriv = dev->private;
 
+       comedi_pci_detach(dev);
        if (devpriv)
                mutex_destroy(&devpriv->mutex);
-       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver dyna_pci10xx_driver = {
index 40a297c6d361005d600a697fe6b39004a27700ca..fedc62e1e23c6938efe51112fcfad718e8091c87 100644 (file)
@@ -542,11 +542,7 @@ static void icp_multi_detach(struct comedi_device *dev)
        if (devpriv)
                if (devpriv->valid)
                        icp_multi_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver icp_multi_driver = {
index f46722c2648fff5aa4fcd8884c8cecb0e7f0b72b..77e94a34b51e680a2bfdeb1b2d028a95070fd403 100644 (file)
@@ -212,7 +212,7 @@ static struct comedi_driver ke_counter_driver = {
        .driver_name    = "ke_counter",
        .module         = THIS_MODULE,
        .auto_attach    = ke_counter_auto_attach,
-       .detach         = comedi_pci_disable,
+       .detach         = comedi_pci_detach,
 };
 
 static int ke_counter_pci_probe(struct pci_dev *dev,
index 3e812f0e32c1e0e47e0f50d2c2b3e45bbeaac701..5b74b36da139766846530384872e4810afe6b147 100644 (file)
@@ -1516,11 +1516,9 @@ static int me4000_auto_attach(struct comedi_device *dev,
 
 static void me4000_detach(struct comedi_device *dev)
 {
-       if (dev->irq)
-               free_irq(dev->irq, dev);
        if (dev->iobase)
                me4000_reset(dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver me4000_driver = {
index 9ff9af6d4262f498eb0c63c70f8325869eb98019..00eaaf8ac148ffe546c8c5d05ede056867627f2f 100644 (file)
@@ -544,14 +544,12 @@ static void me_detach(struct comedi_device *dev)
        struct me_private_data *dev_private = dev->private;
 
        if (dev_private) {
-               if (dev->mmio) {
+               if (dev->mmio)
                        me_reset(dev);
-                       iounmap(dev->mmio);
-               }
                if (dev_private->plx_regbase)
                        iounmap(dev_private->plx_regbase);
        }
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver me_daq_driver = {
index 005376e1951729eb4d41b39b974e75fd9573592f..c8d3a22c5896492f01e045dd80ba04e981e8da59 100644 (file)
@@ -290,14 +290,13 @@ static void mf6x4_detach(struct comedi_device *dev)
 {
        struct mf6x4_private *devpriv = dev->private;
 
-       if (devpriv->bar0_mem)
-               iounmap(devpriv->bar0_mem);
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       if (devpriv->bar2_mem)
-               iounmap(devpriv->bar2_mem);
-
-       comedi_pci_disable(dev);
+       if (devpriv) {
+               if (devpriv->bar0_mem)
+                       iounmap(devpriv->bar0_mem);
+               if (devpriv->bar2_mem)
+                       iounmap(devpriv->bar2_mem);
+       }
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver mf6x4_driver = {
index 7f868b503480e08e605f3e7d85b4c484a5e348e8..45fb601e408009c8ebd8e07123a1a6de352058ba 100644 (file)
@@ -471,11 +471,7 @@ static void ni6527_detach(struct comedi_device *dev)
 {
        if (dev->mmio)
                ni6527_reset(dev);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver ni6527_driver = {
index bf0a50dd897846a8cc1f61e988906f873a2be13a..63a33de75679730daf3b4b0dfe3fd0c7b1cce7ea 100644 (file)
@@ -792,13 +792,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
 static void ni_65xx_detach(struct comedi_device *dev)
 {
-       if (dev->mmio) {
+       if (dev->mmio)
                writeb(0x00, dev->mmio + NI_65XX_CTRL_REG);
-               iounmap(dev->mmio);
-       }
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
+       comedi_pci_detach(dev);
 }
 
 static struct comedi_driver ni_65xx_driver = {
index 092e2b17a5d3e3f51c360f877196ab435dd039ba..54721deb80ccbdad2ea05a6f56105677278cc8f3 100644 (file)
@@ -256,14 +256,12 @@ static void ni_670x_detach(struct comedi_device *dev)
 {
        struct comedi_subdevice *s;
 
+       comedi_pci_detach(dev);
        if (dev->n_subdevices) {
                s = &dev->subdevices[0];
                if (s)
                        kfree(s->range_table_list);
        }
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_670x_driver = {
index 65984ea0a3ee39e2afef2c58c182a44ed2e817b3..3fc42040656427f8f0331a84f8df023e88fb2df2 100644 (file)
@@ -108,20 +108,11 @@ static int labpc_pci_auto_attach(struct comedi_device *dev,
        return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED);
 }
 
-static void labpc_pci_detach(struct comedi_device *dev)
-{
-       if (dev->mmio)
-               iounmap(dev->mmio);
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver labpc_pci_comedi_driver = {
        .driver_name    = "labpc_pci",
        .module         = THIS_MODULE,
        .auto_attach    = labpc_pci_auto_attach,
-       .detach         = labpc_pci_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static const struct pci_device_id labpc_pci_table[] = {
index 342f74e1599a30f89cbf6a97cbd58816636fed8b..869652b36b31cdade490d2edb960a145513ae2a4 100644 (file)
@@ -640,7 +640,7 @@ static void skel_detach(struct comedi_device *dev)
                 * If PCI device enabled by _auto_attach() (or _attach()),
                 * disable it here.
                 */
-               comedi_pci_disable(dev);
+               comedi_pci_detach(dev);
        } else {
                /*
                 * ISA board