summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/comedi_pci.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-08-25 17:55:48 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-08-30 13:24:54 -0700
commitaac307f9dd5ce1fe651140a036ab4b0a0571b54a (patch)
tree28797d71317c989f4b10ecf517641959dfea7cdb /drivers/staging/comedi/comedi_pci.c
parent081b6ee6f1060517a9bcee26418c8ae762c7410e (diff)
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 <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/comedi_pci.c')
-rw-r--r--drivers/staging/comedi/comedi_pci.c24
1 files changed, 24 insertions, 0 deletions
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 <linux/pci.h>
+#include <linux/interrupt.h>
#include "comedidev.h"
@@ -73,6 +74,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
* @driver: comedi_driver struct