Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f072f54 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi_pci: make comedi_pci_disable() safe to call



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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 433121c6
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -57,15 +57,17 @@ 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)
{
	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);

/**
+2 −2
Original line number Diff line number Diff line
@@ -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)
{
}

+3 −7
Original line number Diff line number Diff line
@@ -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);
	}
	comedi_pci_disable(dev);
}

static struct comedi_driver pci_8255_driver = {
+1 −5
Original line number Diff line number Diff line
@@ -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);
}
+1 −6
Original line number Diff line number Diff line
@@ -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 = {
Loading