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
......@@ -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);
......
......@@ -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)
{
}
......
......@@ -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 = {
......
......@@ -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);
}
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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,
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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,
......
......@@ -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,
......
......@@ -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,
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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 = {
......
......@@ -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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment