staging: comedi: adl_pci9118: store the pci_dev in the comedi_device
authorH Hartley Sweeten <hartleys@visionengravers.com>
Thu, 19 Jul 2012 01:29:15 +0000 (18:29 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jul 2012 23:19:41 +0000 (16:19 -0700)
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/adl_pci9118.c

index 4482aabb3dcc0a252f0ac00dba7a6df0db76e81e..a1f74c2590e8a2e10ab398aeccda002af4c81bd5 100644 (file)
@@ -250,7 +250,6 @@ struct boardtype {
 struct pci9118_private {
        unsigned long iobase_a; /* base+size for AMCC chip */
        unsigned int master;    /* master capable */
-       struct pci_dev *pcidev; /* ptr to actual pcidev */
        unsigned int usemux;    /* we want to use external multiplexor! */
 #ifdef PCI9118_PARANOIDCHECK
        unsigned short chanlist[PCI9118_CHANLEN + 1];   /*
@@ -2151,6 +2150,7 @@ static struct pci_dev *pci9118_find_pci(struct comedi_device *dev,
 static int pci9118_attach(struct comedi_device *dev,
                          struct comedi_devconfig *it)
 {
+       struct pci_dev *pcidev;
        struct comedi_subdevice *s;
        int ret, pages, i;
        unsigned short master;
@@ -2170,16 +2170,17 @@ static int pci9118_attach(struct comedi_device *dev,
                return -ENOMEM;
        }
 
-       devpriv->pcidev = pci9118_find_pci(dev, it);
-       if (!devpriv->pcidev)
+       pcidev = pci9118_find_pci(dev, it);
+       if (!pcidev)
                return -EIO;
+       comedi_set_hw_dev(dev, &pcidev->dev);
 
        if (master)
-               pci_set_master(devpriv->pcidev);
+               pci_set_master(pcidev);
 
-       irq = devpriv->pcidev->irq;
-       devpriv->iobase_a = pci_resource_start(devpriv->pcidev, 0);
-       dev->iobase = pci_resource_start(devpriv->pcidev, 2);
+       irq = pcidev->irq;
+       devpriv->iobase_a = pci_resource_start(pcidev, 0);
+       dev->iobase = pci_resource_start(pcidev, 2);
 
        dev->board_name = this_board->name;
 
@@ -2264,8 +2265,8 @@ static int pci9118_attach(struct comedi_device *dev,
 
        printk(".\n");
 
-       pci_read_config_word(devpriv->pcidev, PCI_COMMAND, &u16w);
-       pci_write_config_word(devpriv->pcidev, PCI_COMMAND, u16w | 64);
+       pci_read_config_word(pcidev, PCI_COMMAND, &u16w);
+       pci_write_config_word(pcidev, PCI_COMMAND, u16w | 64);
                                /* Enable parity check for parity error */
 
        ret = comedi_alloc_subdevices(dev, 4);
@@ -2343,17 +2344,13 @@ static int pci9118_attach(struct comedi_device *dev,
 
 static void pci9118_detach(struct comedi_device *dev)
 {
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
        if (dev->private) {
                if (devpriv->valid)
                        pci9118_reset(dev);
                if (dev->irq)
                        free_irq(dev->irq, dev);
-               if (devpriv->pcidev) {
-                       if (dev->iobase)
-                               comedi_pci_disable(devpriv->pcidev);
-
-                       pci_dev_put(devpriv->pcidev);
-               }
                if (devpriv->dmabuf_virt[0])
                        free_pages((unsigned long)devpriv->dmabuf_virt[0],
                                   devpriv->dmabuf_pages[0]);
@@ -2361,6 +2358,12 @@ 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);
+
+               pci_dev_put(pcidev);
+       }
 }
 
 static const struct boardtype boardtypes[] = {