From: H Hartley Sweeten Date: Tue, 26 Aug 2014 00:55:48 +0000 (-0700) Subject: staging: comedi: comedi_pci: introduce comedi_pci_detach() X-Git-Tag: firefly_0821_release~176^2~3121^2~996 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aac307f9dd5ce1fe651140a036ab4b0a0571b54a;p=firefly-linux-kernel-4.4.55.git staging: comedi: comedi_pci: introduce comedi_pci_detach() 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c index abbc0e4f5c51..aa0795a2660e 100644 --- a/drivers/staging/comedi/comedi_pci.c +++ b/drivers/staging/comedi/comedi_pci.c @@ -17,6 +17,7 @@ */ #include +#include #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 diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index a883862b1feb..bda53047d256 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -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 diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index 8bcb1e0e6a71..8b9589828855 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -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, diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c index de5843ab01ae..025b4513f0af 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_common.c +++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c @@ -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); } diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index 44080f6c887f..840cb289507a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c index e9c5291c77cd..5cd396858aa6 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1516.c +++ b/drivers/staging/comedi/drivers/addi_apci_1516.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c index 0940c0da96d5..fb6a78153529 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1564.c +++ b/drivers/staging/comedi/drivers/addi_apci_1564.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 28df4b50b87a..4162e2dc2860 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -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, diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 6768d1dc2005..45ea4a4e451b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index e1a916546d18..51ab1f937bae 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index 0b77f1012d47..050c72493298 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 56781c155343..010efa3fed6c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index 1f59f1681831..57e6f889d73f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c index 1e8b0905a845..0ad46fe492c9 100644 --- a/drivers/staging/comedi/drivers/adl_pci6208.c +++ b/drivers/staging/comedi/drivers/adl_pci6208.c @@ -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, diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c index 5e3cc77a8a0c..fb8e5f582496 100644 --- a/drivers/staging/comedi/drivers/adl_pci7x3x.c +++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c @@ -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, diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index 300df55a2802..72bccb447a74 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -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, diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c index 9ba367e27e93..d18d8f21af23 100644 --- a/drivers/staging/comedi/drivers/adl_pci9111.c +++ b/drivers/staging/comedi/drivers/adl_pci9111.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index f30b84e1987b..6fc50b3735c0 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -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); } diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index e19ab958791b..3e37b0b6f37a 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c index 1881df459dae..1610e2b406f3 100644 --- a/drivers/staging/comedi/drivers/adv_pci1723.c +++ b/drivers/staging/comedi/drivers/adv_pci1723.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c index bc3c34916768..2697758b1ed9 100644 --- a/drivers/staging/comedi/drivers/adv_pci1724.c +++ b/drivers/staging/comedi/drivers/adv_pci1724.c @@ -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, diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index f3e2268d4fee..8aab4949a96c 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c index 423b6249d4f1..b83d1f5a8fb9 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_pci.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_pci.c @@ -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[] = { diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c index ba247741adaf..b65cd484d61e 100644 --- a/drivers/staging/comedi/drivers/amplc_pci224.c +++ b/drivers/staging/comedi/drivers/amplc_pci224.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 2fc499217377..0da5a4a47961 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -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); } diff --git a/drivers/staging/comedi/drivers/amplc_pci236.c b/drivers/staging/comedi/drivers/amplc_pci236.c index 436aebaf7621..ad1e93dd13a0 100644 --- a/drivers/staging/comedi/drivers/amplc_pci236.c +++ b/drivers/staging/comedi/drivers/amplc_pci236.c @@ -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[] = { diff --git a/drivers/staging/comedi/drivers/amplc_pci263.c b/drivers/staging/comedi/drivers/amplc_pci263.c index 748a6b108f32..2259bee98d48 100644 --- a/drivers/staging/comedi/drivers/amplc_pci263.c +++ b/drivers/staging/comedi/drivers/amplc_pci263.c @@ -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[] = { diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index b2be8f3251e1..a0bb4c869044 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index 91ba90b5ceae..01875d7c376f 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -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, diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index 1bbe769c30b5..fe4d2544f3dc 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -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, diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 361213cdc58e..03043e7b9b58 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c @@ -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, diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c index f066fb06dc1d..205f9df345a2 100644 --- a/drivers/staging/comedi/drivers/contec_pci_dio.c +++ b/drivers/staging/comedi/drivers/contec_pci_dio.c @@ -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, diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index dc299f6fa611..e5b5a8133b34 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/das08_pci.c b/drivers/staging/comedi/drivers/das08_pci.c index 4ce3eb0a64cc..0987ce554945 100644 --- a/drivers/staging/comedi/drivers/das08_pci.c +++ b/drivers/staging/comedi/drivers/das08_pci.c @@ -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, diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index bcbba09b083a..ab1fe4a4ac61 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -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, diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c index e5593f8c7406..608aee0c3a15 100644 --- a/drivers/staging/comedi/drivers/dyna_pci10xx.c +++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c index 40a297c6d361..fedc62e1e23c 100644 --- a/drivers/staging/comedi/drivers/icp_multi.c +++ b/drivers/staging/comedi/drivers/icp_multi.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index f46722c2648f..77e94a34b51e 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -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, diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 3e812f0e32c1..5b74b36da139 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 9ff9af6d4262..00eaaf8ac148 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/mf6x4.c b/drivers/staging/comedi/drivers/mf6x4.c index 005376e19517..c8d3a22c5896 100644 --- a/drivers/staging/comedi/drivers/mf6x4.c +++ b/drivers/staging/comedi/drivers/mf6x4.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index 7f868b503480..45fb601e4080 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index bf0a50dd8978..63a33de75679 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c index 092e2b17a5d3..54721deb80cc 100644 --- a/drivers/staging/comedi/drivers/ni_670x.c +++ b/drivers/staging/comedi/drivers/ni_670x.c @@ -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 = { diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c index 65984ea0a3ee..3fc420406564 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_pci.c +++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c @@ -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[] = { diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c index 342f74e1599a..869652b36b31 100644 --- a/drivers/staging/comedi/drivers/skel.c +++ b/drivers/staging/comedi/drivers/skel.c @@ -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