From af12717c18e7b59961926bde71c5cd83cc8379f7 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Thu, 3 Mar 2005 23:13:20 +0000 Subject: [PATCH] patch from Ian Abbott : updates the drivers to use pci_get_device() instead of pci_find_device() and fixes a few other bits that seemed to be broken: mostly insufficient checking in the 'detach' routines. --- comedi/drivers/adl_pci6208.c | 9 ++++++--- comedi/drivers/adl_pci9111.c | 15 ++++++++++++--- comedi/drivers/adv_pci_dio.c | 10 +++++++--- comedi/drivers/amcc_s5933.c | 12 +++++++++--- comedi/drivers/amplc_dio200.c | 13 ++++++++++--- comedi/drivers/amplc_pc236.c | 13 ++++++++++--- comedi/drivers/amplc_pc263.c | 5 +++++ comedi/drivers/amplc_pci230.c | 16 ++++++++++++---- comedi/drivers/cb_pcidas.c | 2 ++ comedi/drivers/cb_pcidas64.c | 8 ++++++-- comedi/drivers/cb_pcidda.c | 7 +++++-- comedi/drivers/cb_pcimdas.c | 22 +++++++++++++++------- comedi/drivers/cb_pcimdda.c | 8 ++++++-- comedi/drivers/contec_pci_dio.c | 8 ++++++-- comedi/drivers/daqboard2000.c | 15 +++++++++++++-- comedi/drivers/das08.c | 11 +++++++---- comedi/drivers/dt3000.c | 6 ++++-- comedi/drivers/gsc_hpdi.c | 3 +++ comedi/drivers/ke_counter.c | 26 ++++++++++++++++++++++++-- comedi/drivers/me4000.c | 20 ++++++++++++-------- comedi/drivers/me_daq.c | 17 ++++++++++++++--- comedi/drivers/mite.c | 8 +++++--- comedi/drivers/rtd520.c | 14 +++++++++++--- 23 files changed, 204 insertions(+), 64 deletions(-) diff --git a/comedi/drivers/adl_pci6208.c b/comedi/drivers/adl_pci6208.c index c3a455c4..29706560 100644 --- a/comedi/drivers/adl_pci6208.c +++ b/comedi/drivers/adl_pci6208.c @@ -204,7 +204,10 @@ static int pci6208_detach(comedi_device *dev) { printk("comedi%d: pci6208: remove\n",dev->minor); - pci_release_regions(devpriv->pci_dev); + if(devpriv && devpriv->pci_dev){ + pci_release_regions(devpriv->pci_dev); + pci_dev_put(devpriv->pci_dev); + } return 0; } @@ -303,8 +306,8 @@ pci6208_find_device(comedi_device *dev, int bus, int slot) struct pci_dev *pci_dev; int i; - for(pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; - pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { + for(pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; + pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { if (pci_dev->vendor == PCI_VENDOR_ID_ADLINK) { for (i= 0; i< pci6208_board_nbr; i++) diff --git a/comedi/drivers/adl_pci9111.c b/comedi/drivers/adl_pci9111.c index 312f3967..809ca476 100644 --- a/comedi/drivers/adl_pci9111.c +++ b/comedi/drivers/adl_pci9111.c @@ -1268,8 +1268,8 @@ static int pci9111_attach(comedi_device *dev,comedi_devconfig *it) printk("comedi%d: " PCI9111_DRIVER_NAME " driver\n",dev->minor); - for(pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) + for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; + pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { if (pci_device->vendor == PCI_VENDOR_ID_ADLINK) { @@ -1340,6 +1340,7 @@ found: if(pci_request_regions(pci_device, PCI9111_DRIVER_NAME)) { printk("comedi%d: I/O port conflict\n",dev->minor); + pci_dev_put(pci_device); return -EIO; } @@ -1347,7 +1348,11 @@ found: dev->board_name = board->name; if(alloc_private(dev,sizeof(pci9111_private_data_struct))<0) + { + pci_release_regions(pci_device); + pci_dev_put(pci_device); return -ENOMEM; + } dev_private->pci_device = pci_device; dev_private->io_range = io_range; @@ -1457,7 +1462,11 @@ static int pci9111_detach(comedi_device *dev) comedi_free_irq(dev->irq,dev); } - pci_release_regions(dev_private->pci_device); + if (dev_private!=0 && dev_private->pci_device!=0) + { + pci_release_regions(dev_private->pci_device); + pci_dev_put(dev_private->pci_device); + } return 0; } diff --git a/comedi/drivers/adv_pci_dio.c b/comedi/drivers/adv_pci_dio.c index 286b560c..21012bbc 100644 --- a/comedi/drivers/adv_pci_dio.c +++ b/comedi/drivers/adv_pci_dio.c @@ -896,8 +896,8 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) return -ENOMEM; } - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if ((pcidev->vendor!=this_board->vendor_id)|| (pcidev->device!=this_board->device_id)) continue; @@ -911,6 +911,7 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) if (ret==1) { found=1; break; } if (ret>1) { pci_dio_detach(dev); + pci_dev_put(pcidev); return -EIO; } } @@ -928,6 +929,7 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) if (pci_request_regions(pcidev, driver_pci_dio.driver_name)) { pci_dio_detach(dev); + pci_dev_put(pcidev); rt_printk(", Error: Cann't allocate PCI device!\n"); return -EIO; } @@ -1048,8 +1050,10 @@ static int pci_dio_detach(comedi_device *dev) if (devpriv->enabled) pci_disable_device(devpriv->pcidev); - if (devpriv->pcidev) + if (devpriv->pcidev) { pci_release_regions(devpriv->pcidev); + pci_dev_put(devpriv->pcidev); + } if (devpriv->prev) { devpriv->prev->next=devpriv->next; } { pci_priv=devpriv->next; } diff --git a/comedi/drivers/amcc_s5933.c b/comedi/drivers/amcc_s5933.c index 5fe23d17..d0624835 100644 --- a/comedi/drivers/amcc_s5933.c +++ b/comedi/drivers/amcc_s5933.c @@ -31,13 +31,18 @@ void pci_card_list_init(unsigned short pci_vendor, char display) amcc_devices=NULL; last=NULL; - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if(pcidev->vendor==pci_vendor){ amcc=kmalloc(sizeof(*amcc),GFP_KERNEL); + if (!amcc) { + printk("amcc_s5933: allocation failed\n"); + pci_dev_put(pcidev); + break; + } memset(amcc,0,sizeof(*amcc)); - amcc->pcidev=pcidev; + amcc->pcidev=pci_dev_get(pcidev); if (last) { last->next=amcc; } else { amcc_devices=amcc; } last=amcc; @@ -69,6 +74,7 @@ void pci_card_list_cleanup(unsigned short pci_vendor) struct pcilst_struct *amcc,*next; for(amcc=amcc_devices;amcc;amcc=next){ + pci_dev_put(amcc->pcidev); next=amcc->next; kfree(amcc); } diff --git a/comedi/drivers/amplc_dio200.c b/comedi/drivers/amplc_dio200.c index ae638e5a..c90b6983 100644 --- a/comedi/drivers/amplc_dio200.c +++ b/comedi/drivers/amplc_dio200.c @@ -277,9 +277,9 @@ dio200_find_pci(comedi_device *dev, int bus, int slot, } /* Look for matching PCI device. */ - for(pci_dev = pci_find_device(pci_id->vendor, pci_id->device, NULL); + for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); pci_dev != NULL ; - pci_dev = pci_find_device(pci_id->vendor, + pci_dev = pci_get_device(pci_id->vendor, pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { @@ -755,7 +755,7 @@ static int dio200_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; - struct pci_dev *pci_dev; + struct pci_dev *pci_dev = NULL; int iobase = 0, irq = 0; int bus = 0, slot = 0; dio200_layout *layout; @@ -785,6 +785,7 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) if ((ret=pci_enable_device(pci_dev)) < 0) { printk(KERN_ERR "comedi%d: error! cannot enable PCI device!\n", dev->minor); + pci_dev_put(pci_dev); return ret; } iobase = pci_resource_start(pci_dev, 2); @@ -799,6 +800,9 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) if ((ret=alloc_private(dev,sizeof(dio200_private))) < 0) { printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor); + if (pci_dev) { + pci_dev_put(pci_dev); + } return ret; } @@ -927,6 +931,9 @@ dio200_detach(comedi_device *dev) if (dev->iobase) { release_region(dev->iobase, DIO200_IO_SIZE); } + if (devpriv && devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } if (dev->board_name) { printk(KERN_INFO "comedi%d: %s removed\n", dev->minor, dev->board_name); diff --git a/comedi/drivers/amplc_pc236.c b/comedi/drivers/amplc_pc236.c index a5a8e657..900f1f69 100644 --- a/comedi/drivers/amplc_pc236.c +++ b/comedi/drivers/amplc_pc236.c @@ -198,9 +198,9 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) } /* Look for matching PCI device. */ - for(pci_dev = pci_find_device(pci_id->vendor, pci_id->device, + for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); pci_dev != NULL; - pci_dev = pci_find_device(pci_id->vendor, + pci_dev = pci_get_device(pci_id->vendor, pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { @@ -229,6 +229,7 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) } if ((ret=pci_enable_device(pci_dev)) < 0) { printk("error enabling PCI device!\n"); + pci_dev_put(pci_dev); return ret; } lcr_iobase = pci_resource_start(pci_dev, 1); @@ -253,6 +254,8 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) */ if ((ret=alloc_private(dev,sizeof(pc236_private))) < 0) { printk("out of memory!\n"); + if (pci_dev) + pci_dev_put(pci_dev); return ret; } @@ -344,11 +347,15 @@ static int pc236_detach(comedi_device *dev) if (dev->subdevices) { subdev_8255_cleanup(dev, dev->subdevices+0); } + if (dev->iobase) { + release_region(dev->iobase, PC236_IO_SIZE); + } if (devpriv) { if (devpriv->lcr_iobase) release_region(devpriv->lcr_iobase, PC236_LCR_IO_SIZE); + if (devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); } - if (dev->iobase) release_region(dev->iobase, PC236_IO_SIZE); return 0; } diff --git a/comedi/drivers/amplc_pc263.c b/comedi/drivers/amplc_pc263.c index 9a260b24..e621c635 100644 --- a/comedi/drivers/amplc_pc263.c +++ b/comedi/drivers/amplc_pc263.c @@ -200,6 +200,7 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) } if ((ret=pci_enable_device(pci_dev)) < 0) { printk("error enabling PCI device!\n"); + pci_dev_put(pci_dev); return ret; } iobase = pci_resource_start(pci_dev, 2); @@ -222,6 +223,8 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) */ if ((ret=alloc_private(dev,sizeof(pc263_private))) < 0) { printk("out of memory!\n"); + if (pci_dev) + pci_dev_put(pci_dev); return ret; } @@ -285,6 +288,8 @@ static int pc263_detach(comedi_device *dev) if (dev->iobase) release_region(dev->iobase, PC263_IO_SIZE); + if (devpriv && devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); return 0; } diff --git a/comedi/drivers/amplc_pci230.c b/comedi/drivers/amplc_pci230.c index 35c559e2..ba16ac6d 100644 --- a/comedi/drivers/amplc_pci230.c +++ b/comedi/drivers/amplc_pci230.c @@ -332,8 +332,8 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) printk("comedi%d: amplc_pci230\n",dev->minor); /* Find card */ - for(pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; - pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { + for(pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; + pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { if(pci_dev->vendor != PCI_VENDOR_ID_AMPLICON) continue; for(i=0;iboard_ptr = pci230_boards+i; /* Read base addressses of the PCI230's two I/O regions from PCI configuration register. */ - if(pci_enable_device(pci_dev)<0)return -EIO; + if(pci_enable_device(pci_dev)<0){ + pci_dev_put(pci_dev); + return -EIO; + } pci_iobase = pci_resource_start(pci_dev, 2); iobase = pci_resource_start(pci_dev, 3); @@ -359,8 +362,10 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) /* Allocate the private structure area using alloc_private(). * Macro defined in comedidev.h - memsets struct fields to 0. */ - if((alloc_private(dev,sizeof(struct pci230_private)))<0) + if((alloc_private(dev,sizeof(struct pci230_private)))<0){ + pci_dev_put(pci_dev); return -ENOMEM; + } devpriv->pci_dev = pci_dev; /* Reserve I/O space 1. */ @@ -486,6 +491,9 @@ static int pci230_detach(comedi_device *dev) if(devpriv->pci_iobase){ release_region(devpriv->pci_iobase, PCI230_IO1_SIZE); } + if(devpriv->pci_dev){ + pci_dev_put(devpriv->pci_dev); + } } return 0; diff --git a/comedi/drivers/cb_pcidas.c b/comedi/drivers/cb_pcidas.c index aec68c2b..2cec0496 100644 --- a/comedi/drivers/cb_pcidas.c +++ b/comedi/drivers/cb_pcidas.c @@ -769,6 +769,8 @@ static int cb_pcidas_detach(comedi_device *dev) comedi_free_irq(dev->irq, dev); if(dev->subdevices) subdev_8255_cleanup(dev,dev->subdevices + 2); + if(devpriv && devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); return 0; } diff --git a/comedi/drivers/cb_pcidas64.c b/comedi/drivers/cb_pcidas64.c index a0d70b0d..14caf9f2 100644 --- a/comedi/drivers/cb_pcidas64.c +++ b/comedi/drivers/cb_pcidas64.c @@ -1660,8 +1660,8 @@ static int attach(comedi_device *dev, comedi_devconfig *it) * Probe the device to determine what device in the series it is. */ - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? if( pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS ) @@ -1697,7 +1697,10 @@ static int attach(comedi_device *dev, comedi_devconfig *it) pcidev->bus->number, PCI_SLOT(pcidev->devfn)); if( pci_enable_device( pcidev ) ) + { + pci_dev_put( pcidev ); return -EIO; + } pci_set_master( pcidev ); priv(dev)->hw_dev = pcidev; @@ -1817,6 +1820,7 @@ static int detach(comedi_device *dev) pci_free_consistent(priv(dev)->hw_dev, sizeof(struct plx_dma_desc) * AO_DMA_RING_COUNT, priv(dev)->ao_dma_desc, priv(dev)->ao_dma_desc_bus_addr ); pci_disable_device(priv(dev)->hw_dev); + pci_dev_put(priv(dev)->hw_dev); } } if(dev->subdevices) diff --git a/comedi/drivers/cb_pcidda.c b/comedi/drivers/cb_pcidda.c index dc299ea7..5c733b46 100644 --- a/comedi/drivers/cb_pcidda.c +++ b/comedi/drivers/cb_pcidda.c @@ -284,8 +284,8 @@ static int cb_pcidda_attach(comedi_device *dev, comedi_devconfig *it) */ printk("\n"); - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if(pcidev->vendor==PCI_VENDOR_ID_CB){ if(it->options[0] || it->options[1]){ if(pcidev->bus->number==it->options[0] && @@ -310,6 +310,7 @@ static int cb_pcidda_attach(comedi_device *dev, comedi_devconfig *it) } printk("Not a supported ComputerBoards/MeasurementComputing card on " "requested position\n"); + pci_dev_put(pcidev); return -EIO; found: @@ -408,6 +409,8 @@ static int cb_pcidda_detach(comedi_device *dev) release_region(devpriv->digitalio, DIGITALIO_SIZE); if(devpriv->dac) release_region(devpriv->dac, 8 + thisboard->ao_chans*2); + if(devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); } // cleanup 8255 if(dev->subdevices) diff --git a/comedi/drivers/cb_pcimdas.c b/comedi/drivers/cb_pcimdas.c index 57b8db5e..abd9a9d6 100644 --- a/comedi/drivers/cb_pcimdas.c +++ b/comedi/drivers/cb_pcimdas.c @@ -239,8 +239,8 @@ static int cb_pcimdas_attach(comedi_device *dev,comedi_devconfig *it) */ printk("\n"); - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? if(pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) @@ -407,13 +407,18 @@ found: static int cb_pcimdas_detach(comedi_device *dev) { #ifdef CBPCIMDAS_DEBUG - printk("devpriv->BADR0 = %d\n",devpriv->BADR0); - printk("devpriv->BADR1 = %d\n",devpriv->BADR1); - printk("devpriv->BADR2 = %d\n",devpriv->BADR2); - printk("devpriv->BADR3 = %d\n",devpriv->BADR3); - printk("devpriv->BADR4 = %d\n",devpriv->BADR4); + if(devpriv) + { + printk("devpriv->BADR0 = %d\n",devpriv->BADR0); + printk("devpriv->BADR1 = %d\n",devpriv->BADR1); + printk("devpriv->BADR2 = %d\n",devpriv->BADR2); + printk("devpriv->BADR3 = %d\n",devpriv->BADR3); + printk("devpriv->BADR4 = %d\n",devpriv->BADR4); + } #endif printk("comedi%d: cb_pcimdas: remove\n",dev->minor); + if(devpriv) + { if(devpriv->BADR0) release_mem_region(devpriv->BADR0, BADR0_SIZE); if(devpriv->BADR1) @@ -424,6 +429,9 @@ static int cb_pcimdas_detach(comedi_device *dev) release_region(devpriv->BADR3, BADR3_SIZE); if(devpriv->BADR4) release_region(devpriv->BADR4, BADR4_SIZE); + if(devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); + } if(dev->irq) comedi_free_irq(dev->irq, dev); diff --git a/comedi/drivers/cb_pcimdda.c b/comedi/drivers/cb_pcimdda.c index 6c88e461..d48ed046 100644 --- a/comedi/drivers/cb_pcimdda.c +++ b/comedi/drivers/cb_pcimdda.c @@ -347,6 +347,10 @@ static int detach(comedi_device *dev) devpriv->attached_to_8255 = 0; } + if (devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } + if (devpriv->attached_successfully && thisboard) printk("comedi%d: %s: detached\n", dev->minor, thisboard->name); @@ -438,8 +442,8 @@ static int probe(comedi_device *dev, const comedi_devconfig *it) struct pci_dev *pcidev; int index, registers; - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? if(pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) diff --git a/comedi/drivers/contec_pci_dio.c b/comedi/drivers/contec_pci_dio.c index 3b1ff3b1..b0a56669 100644 --- a/comedi/drivers/contec_pci_dio.c +++ b/comedi/drivers/contec_pci_dio.c @@ -107,11 +107,12 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_subdevices(dev, 2)<0) return -ENOMEM; - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if ( pcidev->vendor == PCI_VENDOR_ID_CONTEC && pcidev->device == PCI_DEVICE_ID_PIO1616L ) { + devpriv->pci_dev = pcidev; dev->iobase = pci_resource_start ( pcidev, 0 ); printk ( " base addr %lx ", dev->iobase ); @@ -146,6 +147,9 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) static int contec_detach(comedi_device *dev) { printk("comedi%d: contec: remove\n",dev->minor); + + if (devpriv && devpriv->pci_dev) + pci_dev_put(devpriv->pci_dev); return 0; } diff --git a/comedi/drivers/daqboard2000.c b/comedi/drivers/daqboard2000.c index 1fe06326..b24f4973 100644 --- a/comedi/drivers/daqboard2000.c +++ b/comedi/drivers/daqboard2000.c @@ -322,6 +322,7 @@ typedef struct { enum { card_daqboard_2000 } card; + struct pci_dev *pci_dev; void *daq; void *plx; lsampl_t ao_readback[2]; @@ -684,7 +685,7 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) /* FIXME: we should handle multiple cards, have to make David decide how, so we will be consistent among all PCI card drivers... */ - card = pci_find_device(0x1616, 0x0409, NULL); + card = pci_get_device(0x1616, 0x0409, NULL); if (!card) { printk(" no daqboard2000 found\n"); @@ -693,6 +694,7 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) } if((result = pci_enable_device(card))<0){ + pci_dev_put(card); goto out; } @@ -713,11 +715,17 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) }else{ printk(" abnormal pci header type !?!?\n"); result=-EIO; + pci_dev_put(card); goto out; } result = alloc_private(dev,sizeof(daqboard2000_private)); - if(result<0)goto out; + if(result<0){ + pci_dev_put(card); + goto out; + } + + devpriv->pci_dev = card; result = alloc_subdevices(dev, 3); if(result<0)goto out; @@ -799,6 +807,9 @@ static int daqboard2000_detach(comedi_device * dev) if (dev->irq) { free_irq(dev->irq, dev); } + if (devpriv && devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } return 0; } diff --git a/comedi/drivers/das08.c b/comedi/drivers/das08.c index ebba53da..8715e8ab 100644 --- a/comedi/drivers/das08.c +++ b/comedi/drivers/das08.c @@ -459,7 +459,7 @@ struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS]={ do_nchan: 3, i8255_offset: 0, i8254_offset: 0, - iosize: 16, // unchecked + iosize: 16, }, // duplicate so driver name can be used also { @@ -477,7 +477,7 @@ struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS]={ do_nchan: 3, i8255_offset: 0, i8254_offset: 0, - iosize: 16, // unchecked + iosize: 16, }, }; @@ -943,8 +943,8 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it) } printk("\n"); // find card - for(pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pdev != NULL ; - pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) { + for(pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pdev != NULL ; + pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) { if(pdev->vendor == PCI_VENDOR_ID_COMPUTERBOARDS && pdev->device == PCI_DEVICE_ID_PCIDAS08){ if(it->options[0] || it->options[1]){ @@ -1012,6 +1012,9 @@ int das08_common_detach(comedi_device *dev) if(devpriv->pci_iobase){ release_region(devpriv->pci_iobase, PCIDAS08_SIZE); } + if(devpriv->pdev){ + pci_dev_put(devpriv->pdev); + } } return 0; diff --git a/comedi/drivers/dt3000.c b/comedi/drivers/dt3000.c index d8532ac6..81a355fd 100644 --- a/comedi/drivers/dt3000.c +++ b/comedi/drivers/dt3000.c @@ -841,6 +841,8 @@ static int dt3000_detach(comedi_device *dev) { if(dev->irq)comedi_free_irq(dev->irq,dev); + if(devpriv && devpriv->pci_dev) pci_dev_put(devpriv->pci_dev); + /* XXX */ return 0; @@ -892,8 +894,8 @@ static struct pci_dev *dt_pci_find_device(struct pci_dev *from,int *board) { int i; - for(from=pci_find_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from); from!=NULL; - from=pci_find_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from)){ + for(from=pci_get_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from); from!=NULL; + from=pci_get_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from)){ for(i=0;idevice == dt3k_boardtypes[i].device_id){ *board=i; diff --git a/comedi/drivers/gsc_hpdi.c b/comedi/drivers/gsc_hpdi.c index 00b5b104..d485a1f7 100644 --- a/comedi/drivers/gsc_hpdi.c +++ b/comedi/drivers/gsc_hpdi.c @@ -575,7 +575,10 @@ static int hpdi_attach(comedi_device *dev, comedi_devconfig *it) pcidev->bus->number, PCI_SLOT(pcidev->devfn)); if( pci_enable_device( pcidev ) ) + { + pci_dev_put( pcidev ); return -EIO; + } pci_set_master( pcidev ); priv(dev)->hw_dev = pcidev; diff --git a/comedi/drivers/ke_counter.c b/comedi/drivers/ke_counter.c index 0685c7e9..658084a2 100644 --- a/comedi/drivers/ke_counter.c +++ b/comedi/drivers/ke_counter.c @@ -74,6 +74,15 @@ static cnt_board_struct cnt_boards[] = #define cnt_board_nbr (sizeof(cnt_boards)/sizeof(cnt_board_struct)) +/*-- device private structure -----------------------------------------------*/ + +typedef struct +{ + struct pci_dev *pcidev; +} cnt_device_private; + +#define devpriv ((cnt_device_private *)dev->private) + static comedi_driver cnt_driver = { driver_name: CNT_DRIVER_NAME, @@ -140,8 +149,8 @@ static int cnt_attach(comedi_device *dev, comedi_devconfig *it) int error, i; /* Probe the device to determine what device in the series it is. */ - for(pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) + for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; + pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { if(pci_device->vendor == PCI_VENDOR_ID_KOLTER) { @@ -181,6 +190,15 @@ found: request_region(io_base & PCI_BASE_ADDRESS_IO_MASK, 0x08, CNT_DRIVER_NAME); dev->iobase = io_base & PCI_BASE_ADDRESS_IO_MASK; + /* allocate device private structure */ + if((error = alloc_private(dev, sizeof(cnt_device_private))) < 0) + { + pci_dev_put(pci_device); + return error; + } + + devpriv->pcidev = pci_device; + /* allocate the subdevice structures */ if((error = alloc_subdevices(dev, 1)) < 0) { @@ -217,6 +235,10 @@ static int cnt_detach(comedi_device *dev) { release_region(dev->iobase, 0x08); } + if (devpriv->pcidev) + { + pci_dev_put(devpriv->pcidev); + } printk("comedi%d: " CNT_DRIVER_NAME " remove\n",dev->minor); return 0; diff --git a/comedi/drivers/me4000.c b/comedi/drivers/me4000.c index a4b82150..cea0e2fa 100644 --- a/comedi/drivers/me4000.c +++ b/comedi/drivers/me4000.c @@ -397,8 +397,8 @@ static int me4000_probe(comedi_device *dev, comedi_devconfig *it){ /* * Probe the device to determine what device in the series it is. */ - for(pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { + for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; + pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { if(pci_device->vendor == PCI_VENDOR_ID_MEILHAUS){ for(i = 0; i < ME4000_BOARD_VERSIONS; i++){ if(me4000_boards[i].device_id == pci_device->device){ @@ -430,8 +430,10 @@ found: pci_device->bus->number, PCI_SLOT(pci_device->devfn)); /* Allocate private memory */ - if(alloc_private(dev, sizeof(me4000_info_t)) < 0) + if(alloc_private(dev, sizeof(me4000_info_t)) < 0){ + pci_dev_put(pci_device); return -ENOMEM; + } /* Set data in device structure */ dev->board_name = board->name; @@ -506,7 +508,6 @@ PROBE_ERROR_2: pci_release_regions(pci_device); PROBE_ERROR_1: - kfree(info); return result; } @@ -847,11 +848,14 @@ static int reset_board(comedi_device *dev){ static int me4000_detach(comedi_device *dev){ CALL_PDEBUG("In me4000_detach()\n"); - reset_board(dev); - - pci_release_regions(info->pci_dev_p); + if(info){ + reset_board(dev); - kfree(info); + if(info->pci_dev_p) { + pci_release_regions(info->pci_dev_p); + pci_dev_put(info->pci_dev_p); + } + } return 0; } diff --git a/comedi/drivers/me_daq.c b/comedi/drivers/me_daq.c index 2785d7ad..8931feb3 100644 --- a/comedi/drivers/me_daq.c +++ b/comedi/drivers/me_daq.c @@ -684,8 +684,8 @@ static int me_attach(comedi_device *dev,comedi_devconfig *it) // // Probe the device to determine what device in the series it is. // - for(pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) + for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; + pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { if(pci_device->vendor == PCI_VENDOR_ID_MEILHAUS) { @@ -725,7 +725,10 @@ found: // Allocate private memory if(alloc_private(dev,sizeof(me_private_data_struct)) < 0) + { + pci_dev_put(pci_device); return -ENOMEM; + } // Set data in device structure @@ -866,7 +869,15 @@ found: static int me_detach(comedi_device *dev) { - me_reset(dev); + if(dev_private) + { + me_reset(dev); + + if(dev_private->pci_device) + { + pci_dev_put(dev_private->pci_device); + } + } return 0; } diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index d8a8918a..554dcc34 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -72,17 +72,18 @@ void mite_init(void) struct pci_dev *pcidev; struct mite_struct *mite; - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if(pcidev->vendor==PCI_VENDOR_ID_NATINST){ mite=kmalloc(sizeof(*mite),GFP_KERNEL); if(!mite){ printk("mite: allocation failed\n"); + pci_dev_put(pcidev); return; } memset(mite,0,sizeof(*mite)); - mite->pcidev=pcidev; + mite->pcidev=pci_dev_get(pcidev); mite->next=mite_devices; mite_devices=mite; @@ -141,6 +142,7 @@ void mite_cleanup(void) struct mite_struct *mite,*next; for(mite=mite_devices;mite;mite=next){ + pci_dev_put(mite->pcidev); next=mite->next; kfree(mite); } diff --git a/comedi/drivers/rtd520.c b/comedi/drivers/rtd520.c index 71df9d86..1781a805 100644 --- a/comedi/drivers/rtd520.c +++ b/comedi/drivers/rtd520.c @@ -774,8 +774,8 @@ static int rtd_attach ( /* * Probe the device to determine what device in the series it is. */ - for(pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if (pcidev->vendor == PCI_VENDOR_ID_RTD) { if (it->options[0] || it->options[1]) { if (pcidev->bus->number == it->options[0] @@ -800,12 +800,12 @@ static int rtd_attach ( return -EIO; } + devpriv->pci_dev = pcidev; if (pcidev->device != thisboard->device_id) { printk ("Found an RTD card, but not the supported type (%x).\n", pcidev->device); return -EIO; } - devpriv->pci_dev = pcidev; dev->board_name = thisboard->name; if((ret=pci_enable_device(pcidev))<0){ @@ -1022,6 +1022,7 @@ static int rtd_attach ( return 1; +#if 0 /* hit an error, clean up memory and return ret */ //rtd_attach_die_error: #ifdef USE_DMA @@ -1063,7 +1064,11 @@ static int rtd_attach ( if (devpriv->lcfg) { iounmap (devpriv->lcfg); } + if (devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } return ret; +#endif } /* @@ -1139,6 +1144,9 @@ static int rtd_detach ( if (devpriv->lcfg) { iounmap (devpriv->lcfg); } + if (devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } } printk("comedi%d: rtd520: removed.\n",dev->minor); -- 2.26.2