From: Frank Mori Hess Date: Sat, 4 Jun 2005 14:32:48 +0000 (+0000) Subject: Patch from Ian Abbot : X-Git-Tag: branch-0_7-end~54 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=78f34fae84cee787d48a313193225d034d3c7565;p=comedi.git Patch from Ian Abbot : I've done some work on getting rid of the check_region calls which are now deprecated. I first mentioned this back in March and did a little bit of work on it at the time: https://cvs.comedi.org/pipermail/comedi/2005-March/006971.html https://cvs.comedi.org/pipermail/comedi/2005-March/006977.html My new patch seems to be too large for the comedi mailing list - they just disappear into a black hole, so here is a description of my latest patch: I used a static inline function called compat__request_region and (re)defined a macro called request_region to use it. The result is that drivers can check the return value of request_region (or pci_request_regions) instead of calling check_region. Note that the compat__request_region does not return a pointer to anything real, but it can be compared to NULL. The attached patch implements the above compatibility stuff and changes the drivers to use it (but I changed the amplc_pci230 driver to use pci_request_regions instead of request_region while I was at it). I've also changed the compatibility version of pci_request_regions to avoid calling check_regions (otherwise it would be called twice) and also made it release any regions it successfully requested on failure. Most of the changes to the individual drivers were straightforward. One or two required a modicum of thought to release resources on error. --- diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index 3a8679b7..fa752385 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -385,13 +385,11 @@ static int dev_8255_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[i]; printk(" 0x%04x",iobase); - if(check_region(iobase,_8255_SIZE)<0){ + if(!request_region(iobase,_8255_SIZE,"8255")){ printk(" (I/O port conflict)"); dev->subdevices[i].type=COMEDI_SUBD_UNUSED; }else{ - request_region(iobase,_8255_SIZE,"8255"); - subdev_8255_init(dev,dev->subdevices+i,NULL,iobase); } } diff --git a/comedi/drivers/acl7225b.c b/comedi/drivers/acl7225b.c index e0351bc1..d7c0479e 100644 --- a/comedi/drivers/acl7225b.c +++ b/comedi/drivers/acl7225b.c @@ -90,13 +90,11 @@ static int acl7225b_attach(comedi_device *dev,comedi_devconfig *it) iorange=this_board->io_range; printk("comedi%d: acl7225b: board=%s 0x%04x ", dev->minor, this_board->name, iobase); - if( check_region(iobase, iorange) < 0 ) - { + if( !request_region(iobase, iorange, "acl7225b") ) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, iorange, "acl7225b"); - dev->board_name=this_board->name; + dev->board_name=this_board->name; dev->iobase=iobase; dev->irq=0; diff --git a/comedi/drivers/adl_pci6208.c b/comedi/drivers/adl_pci6208.c index 6023e274..ea50c970 100644 --- a/comedi/drivers/adl_pci6208.c +++ b/comedi/drivers/adl_pci6208.c @@ -368,11 +368,6 @@ pci6208_pci_setup(struct pci_dev *pci_dev, int *io_base_ptr, int dev_minor) lcr_io_base, lcr_io_range); - if (check_region (lcr_io_base, lcr_io_range) < 0) { - printk("comedi%d: I/O port conflict\n",dev_minor); - return -EIO; - } - // Read PCI6208 register base address [PCI_BASE_ADDRESS #2]. io_base = pci_resource_start (pci_dev, 2); io_range = pci_resource_end (pci_dev, 2) - io_base +1; @@ -382,13 +377,11 @@ pci6208_pci_setup(struct pci_dev *pci_dev, int *io_base_ptr, int dev_minor) io_base, io_range); - if (check_region (io_base, io_range) < 0) { + // Allocate IO ressources + if (pci_request_regions(pci_dev, PCI6208_DRIVER_NAME) < 0) { printk("comedi%d: I/O port conflict\n",dev_minor); return -EIO; } - - // Allocate IO ressources - pci_request_regions(pci_dev, PCI6208_DRIVER_NAME); *io_base_ptr = io_base; //devpriv->io_range = io_range; diff --git a/comedi/drivers/adl_pci9118.c b/comedi/drivers/adl_pci9118.c index 119c710f..0babd0a3 100644 --- a/comedi/drivers/adl_pci9118.c +++ b/comedi/drivers/adl_pci9118.c @@ -1706,16 +1706,10 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) rt_printk(", b:s:f=%d:%d:%d, io=0x%4x, 0x%4x",pci_bus,pci_slot,pci_func,iobase_9,iobase_a); - if (check_region(iobase_9, this_board->iorange_9118) < 0) { + if (!request_region(iobase_9, this_board->iorange_9118, "ADLink PCI-9118")) { rt_printk("I/O port conflict\n"); return -EIO; } - if (check_region(iobase_a, this_board->iorange_amcc) < 0) { - rt_printk("I/O port conflict\n"); - return -EIO; - } - - request_region(iobase_9, this_board->iorange_9118, "ADLink PCI-9118"); dev->iobase=iobase_9; dev->board_name = this_board->name; @@ -1726,7 +1720,10 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) devpriv->amcc=card; devpriv->pcidev=card->pcidev; - request_region(iobase_a, this_board->iorange_amcc, "ADLink PCI-9118"); + if (!request_region(iobase_a, this_board->iorange_amcc, "ADLink PCI-9118")) { + rt_printk("I/O port conflict\n"); + return -EIO; + } devpriv->iobase_a=iobase_a; if (it->options[3]&2) irq=0; // user don't want use IRQ @@ -1871,7 +1868,7 @@ static int pci9118_detach(comedi_device *dev) { if (dev->private) { if (devpriv->valid) pci9118_reset(dev); - release_region(devpriv->iobase_a,this_board->iorange_amcc); + if (devpriv->iobase_a) release_region(devpriv->iobase_a,this_board->iorange_amcc); if (devpriv->allocated) pci_card_free(devpriv->amcc); if (devpriv->dmabuf_virt[0]) free_pages((unsigned long)devpriv->dmabuf_virt[0],devpriv->dmabuf_pages[0]); if (devpriv->dmabuf_virt[1]) free_pages((unsigned long)devpriv->dmabuf_virt[1],devpriv->dmabuf_pages[1]); diff --git a/comedi/drivers/adv_pci1710.c b/comedi/drivers/adv_pci1710.c index 1fe2e30f..d51298a8 100644 --- a/comedi/drivers/adv_pci1710.c +++ b/comedi/drivers/adv_pci1710.c @@ -1255,13 +1255,12 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) rt_printk(", b:s:f=%d:%d:%d, io=0x%4x",pci_bus,pci_slot,pci_func,iobase); - if (check_region(iobase, this_board->iorange) < 0) { + if (!request_region(iobase, this_board->iorange, "Advantech PCI-1710")) { pci_card_free(card); rt_printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, this_board->iorange, "Advantech PCI-1710"); dev->iobase=iobase; dev->board_name = this_board->name; diff --git a/comedi/drivers/amplc_dio200.c b/comedi/drivers/amplc_dio200.c index c90b6983..e9efe144 100644 --- a/comedi/drivers/amplc_dio200.c +++ b/comedi/drivers/amplc_dio200.c @@ -323,12 +323,11 @@ dio200_find_pci(comedi_device *dev, int bus, int slot, static int dio200_request_region(unsigned minor, unsigned long from, unsigned long extent) { - if (check_region(from, extent) < 0) { + if (!request_region(from, extent, DIO200_DRIVER_NAME)) { printk(KERN_ERR "comedi%d: I/O port conflict (%#lx,%lu)!\n", minor, from, extent); return -EIO; } - request_region(from, extent, DIO200_DRIVER_NAME); return 0; } diff --git a/comedi/drivers/amplc_pc236.c b/comedi/drivers/amplc_pc236.c index 2c4bab78..bccd7ca8 100644 --- a/comedi/drivers/amplc_pc236.c +++ b/comedi/drivers/amplc_pc236.c @@ -366,11 +366,10 @@ static int pc236_detach(comedi_device *dev) */ static int pc236_request_region(unsigned long from, unsigned long extent) { - if (check_region(from, extent) < 0) { + if (!request_region(from, extent, PC236_DRIVER_NAME)) { printk("I/O port conflict (%#lx,%lu)!\n", from, extent); return -EIO; } - request_region(from, extent, PC236_DRIVER_NAME); return 0; } diff --git a/comedi/drivers/amplc_pc263.c b/comedi/drivers/amplc_pc263.c index 6a44acfe..1309c5a7 100644 --- a/comedi/drivers/amplc_pc263.c +++ b/comedi/drivers/amplc_pc263.c @@ -300,11 +300,10 @@ static int pc263_detach(comedi_device *dev) */ static int pc263_request_region(unsigned long from, unsigned long extent) { - if (check_region(from, extent) < 0) { + if (!request_region(from, extent, PC263_DRIVER_NAME)) { printk("I/O port conflict (%#lx,%lu)!\n", from, extent); return -EIO; } - request_region(from, extent, PC263_DRIVER_NAME); return 0; } diff --git a/comedi/drivers/amplc_pci230.c b/comedi/drivers/amplc_pci230.c index abc01dae..08caa601 100644 --- a/comedi/drivers/amplc_pci230.c +++ b/comedi/drivers/amplc_pci230.c @@ -368,20 +368,12 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) } devpriv->pci_dev = pci_dev; - /* Reserve I/O space 1. */ - if(check_region(pci_iobase,PCI230_IO1_SIZE)<0){ - printk("comedi%d: amplc_pci230: I/O space 1 conflict\n",dev->minor); + /* Reserve I/O spaces. */ + if(pci_request_regions(pci_dev,"PCI230")<0){ + printk("comedi%d: amplc_pci230: I/O space conflict\n",dev->minor); return -EIO; } - request_region(pci_iobase,PCI230_IO1_SIZE,"PCI230"); devpriv->pci_iobase = pci_iobase; - - /* Reserve I/O space 2. */ - if(check_region(iobase,PCI230_IO2_SIZE)<0){ - printk("comedi%d: amplc_pci230: I/O space 2 conflict\n",dev->minor); - return -EIO; - } - request_region(iobase,PCI230_IO2_SIZE,"PCI230"); dev->iobase = iobase; /* @@ -481,17 +473,13 @@ static int pci230_detach(comedi_device *dev) if(dev->subdevices && thisboard->have_dio) subdev_8255_cleanup(dev,dev->subdevices + 2); /* Clean up dio subdevice. */ - if(dev->iobase) - release_region(dev->iobase,PCI230_IO2_SIZE); - if(dev->irq) comedi_free_irq(dev->irq, dev); if(devpriv){ - if(devpriv->pci_iobase){ - release_region(devpriv->pci_iobase, PCI230_IO1_SIZE); - } if(devpriv->pci_dev){ + if(devpriv->pci_iobase) + pci_release_regions(devpriv->pci_dev); pci_dev_put(devpriv->pci_dev); } } diff --git a/comedi/drivers/cb_pcidas.c b/comedi/drivers/cb_pcidas.c index 25046ade..0f7a1283 100644 --- a/comedi/drivers/cb_pcidas.c +++ b/comedi/drivers/cb_pcidas.c @@ -575,35 +575,32 @@ found: // reserve io ports err = 0; - if(check_region(s5933_config, AMCC_OP_REG_SIZE) < 0) + if(request_region(s5933_config, AMCC_OP_REG_SIZE, "cb_pcidas")) + devpriv->s5933_config = s5933_config; + else err++; - if(check_region(control_status, CONT_STAT_SIZE) < 0) + if(request_region(control_status, CONT_STAT_SIZE, "cb_pcidas")) + devpriv->control_status = control_status; + else err++; - if(check_region(adc_fifo, ADC_FIFO_SIZE) < 0) + if(request_region(adc_fifo, ADC_FIFO_SIZE, "cb_pcidas")) + devpriv->adc_fifo = adc_fifo; + else err++; - if(check_region(pacer_counter_dio, PACER_SIZE) < 0) + if(request_region(pacer_counter_dio, PACER_SIZE, "cb_pcidas")) + devpriv->pacer_counter_dio = pacer_counter_dio; + else err++; if(thisboard->ao_nchan) - if(check_region(ao_registers, AO_SIZE) < 0) + if(request_region(ao_registers, AO_SIZE, "cb_pcidas")) + devpriv->ao_registers = ao_registers; + else err++; if(err) { printk(" I/O port conflict\n"); return -EIO; } - request_region(s5933_config, AMCC_OP_REG_SIZE, "cb_pcidas"); - devpriv->s5933_config = s5933_config; - request_region(control_status, CONT_STAT_SIZE, "cb_pcidas"); - devpriv->control_status = control_status; - request_region(adc_fifo, ADC_FIFO_SIZE, "cb_pcidas"); - devpriv->adc_fifo = adc_fifo; - request_region(pacer_counter_dio, PACER_SIZE, "cb_pcidas"); - devpriv->pacer_counter_dio = pacer_counter_dio; - if(thisboard->ao_nchan) - { - request_region(ao_registers, AO_SIZE, "cb_pcidas"); - devpriv->ao_registers = ao_registers; - } // get irq if(comedi_request_irq(devpriv->pci_dev->irq, cb_pcidas_interrupt, SA_SHIRQ, "cb_pcidas", dev )) diff --git a/comedi/drivers/comedi_parport.c b/comedi/drivers/comedi_parport.c index 07f64fad..6bfa5189 100644 --- a/comedi/drivers/comedi_parport.c +++ b/comedi/drivers/comedi_parport.c @@ -290,11 +290,10 @@ static int parport_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: parport: 0x%04x ",dev->minor,iobase); - if(check_region(iobase,PARPORT_SIZE)<0){ + if(!request_region(iobase,PARPORT_SIZE,"parport (comedi)")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,PARPORT_SIZE,"parport (comedi)"); dev->iobase=iobase; irq=it->options[1]; diff --git a/comedi/drivers/das08.c b/comedi/drivers/das08.c index c1677af0..4e476197 100644 --- a/comedi/drivers/das08.c +++ b/comedi/drivers/das08.c @@ -819,11 +819,10 @@ int das08_common_attach(comedi_device *dev, unsigned long iobase ) if(thisboard->bustype != pcmcia) { printk(" iobase 0x%lx\n", iobase); - if(check_region(iobase, thisboard->iosize)<0){ + if(!request_region(iobase, thisboard->iosize,"das08")){ printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase, thisboard->iosize,"das08"); } dev->iobase = iobase; @@ -969,11 +968,10 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it) iobase = pci_resource_start(pdev, 2); printk("pcibase 0x%lx ", pci_iobase); // reserve io ports for 9052 pci chip - if(check_region(pci_iobase,PCIDAS08_SIZE)<0){ + if(!request_region(pci_iobase,PCIDAS08_SIZE,"das08")){ printk(" I/O port conflict\n"); return -EIO; } - request_region(pci_iobase,PCIDAS08_SIZE,"das08"); devpriv->pci_iobase = pci_iobase; #if 0 /* We could enable to pci-das08's interrupt here to make it possible diff --git a/comedi/drivers/das16.c b/comedi/drivers/das16.c index ba4f894d..0b8de4cf 100644 --- a/comedi/drivers/das16.c +++ b/comedi/drivers/das16.c @@ -1421,7 +1421,7 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) if(thisboard->size<0x400){ printk(" 0x%04x-0x%04x\n", iobase, iobase+thisboard->size); - if(check_region(iobase,thisboard->size)<0){ + if(!request_region(iobase,thisboard->size,"das16")){ printk(" I/O port conflict\n"); return -EIO; } @@ -1429,12 +1429,13 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) printk(" 0x%04x-0x%04x 0x%04x-0x%04x\n", iobase,iobase+0x0f, iobase+0x400,iobase+0x400+(thisboard->size&0x3ff)); - if(check_region(iobase,0x10) < 0) { + if(!request_region(iobase,0x10,"das16")){ printk(" I/O port conflict: 0x%04x-0x%04x\n", iobase,iobase+0x0f); return -EIO; } - if(check_region(iobase+0x400,thisboard->size&0x3ff)<0){ + if(!request_region(iobase+0x400,thisboard->size&0x3ff,"das16")){ + release_region(iobase, 0x10); printk(" I/O port conflict: 0x%04x-0x%04x\n", iobase+0x400, iobase+0x400+(thisboard->size&0x3ff)); @@ -1442,13 +1443,6 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) } } - if(thisboard->size < 0x400){ - request_region(iobase,thisboard->size,"das16"); - }else{ - request_region(iobase,0x10,"das16"); - request_region(iobase+0x400,thisboard->size&0x3ff,"das16"); - } - dev->iobase = iobase; // probe id bits to make sure they are consistent diff --git a/comedi/drivers/das16m1.c b/comedi/drivers/das16m1.c index 0399476c..3472811a 100644 --- a/comedi/drivers/das16m1.c +++ b/comedi/drivers/das16m1.c @@ -648,16 +648,15 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) printk(" io 0x%x-0x%x 0x%x-0x%x", iobase, iobase + DAS16M1_SIZE, iobase + DAS16M1_82C55, iobase + DAS16M1_82C55 + DAS16M1_SIZE2); - if(check_region(iobase, DAS16M1_SIZE) < 0) { + if(!request_region(iobase, DAS16M1_SIZE, driver_das16m1.driver_name)) { printk(" I/O port conflict\n"); return -EIO; } - if(check_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2) < 0){ + if(!request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2, driver_das16m1.driver_name)) { + release_region(iobase , DAS16M1_SIZE); printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase, DAS16M1_SIZE, driver_das16m1.driver_name); - request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2, driver_das16m1.driver_name); dev->iobase = iobase; /* now for the irq */ diff --git a/comedi/drivers/das1800.c b/comedi/drivers/das1800.c index 0c88596d..b799ab25 100644 --- a/comedi/drivers/das1800.c +++ b/comedi/drivers/das1800.c @@ -617,13 +617,12 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) } /* check if io addresses are available */ - if(check_region(iobase, DAS1800_SIZE) < 0) + if(!request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name)) { printk(" I/O port conflict: failed to allocate ports 0x%x to 0x%x\n", iobase, iobase + DAS1800_SIZE - 1); return -EIO; } - request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name); dev->iobase = iobase; board = das1800_probe(dev); @@ -640,13 +639,12 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) if(thisboard->ao_ability == 2) { iobase2 = iobase + IOBASE2; - if(check_region(iobase2, DAS1800_SIZE) < 0) + if(!request_region(iobase2, DAS1800_SIZE, driver_das1800.driver_name)) { printk(" I/O port conflict: failed to allocate ports 0x%x to 0x%x\n", iobase2, iobase2 + DAS1800_SIZE - 1); return -EIO; } - request_region(iobase2, DAS1800_SIZE, driver_das1800.driver_name); devpriv->iobase2 = iobase2; } diff --git a/comedi/drivers/das6402.c b/comedi/drivers/das6402.c index 5cdfe909..d9706151 100644 --- a/comedi/drivers/das6402.c +++ b/comedi/drivers/das6402.c @@ -311,11 +311,10 @@ static int das6402_attach(comedi_device *dev,comedi_devconfig *it) printk("comedi%d: das6402: 0x%04x",dev->minor,iobase); - if(check_region(iobase,DAS6402_SIZE)<0){ + if(!request_region(iobase,DAS6402_SIZE,"das6402")){ printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase,DAS6402_SIZE,"das6402"); dev->iobase=iobase; /* should do a probe here */ diff --git a/comedi/drivers/das800.c b/comedi/drivers/das800.c index 1895853c..f1d83c4b 100644 --- a/comedi/drivers/das800.c +++ b/comedi/drivers/das800.c @@ -477,12 +477,11 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) } /* check if io addresses are available */ - if(check_region(iobase, DAS800_SIZE) < 0) + if(!request_region(iobase, DAS800_SIZE, "das800")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, DAS800_SIZE, "das800"); dev->iobase = iobase; board = das800_probe(dev); diff --git a/comedi/drivers/dt2801.c b/comedi/drivers/dt2801.c index d7c6829d..eeea7072 100644 --- a/comedi/drivers/dt2801.c +++ b/comedi/drivers/dt2801.c @@ -492,11 +492,10 @@ static int dt2801_attach(comedi_device *dev,comedi_devconfig *it) int n_ai_chans; iobase=it->options[0]; - if(check_region(iobase,DT2801_IOSIZE)<0){ + if(!request_region(iobase, DT2801_IOSIZE, "dt2801")){ comedi_error(dev,"I/O port conflict"); return -EIO; } - request_region(iobase, DT2801_IOSIZE, "dt2801"); dev->iobase=iobase; /* do some checking */ diff --git a/comedi/drivers/dt2811.c b/comedi/drivers/dt2811.c index bcbd86ac..494e0d4b 100644 --- a/comedi/drivers/dt2811.c +++ b/comedi/drivers/dt2811.c @@ -307,11 +307,10 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) printk("comedi%d: dt2811: base=0x%04x\n", dev->minor, iobase); - if (check_region(iobase, DT2811_SIZE) < 0) { + if (!request_region(iobase, DT2811_SIZE, driver_name)) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, DT2811_SIZE, driver_name); dev->iobase = iobase; dev->board_name = this_board->name; diff --git a/comedi/drivers/dt2814.c b/comedi/drivers/dt2814.c index 0b16d549..eea18365 100644 --- a/comedi/drivers/dt2814.c +++ b/comedi/drivers/dt2814.c @@ -241,11 +241,10 @@ static int dt2814_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: dt2814: 0x%04lx ",dev->minor,dev->iobase); - if(check_region(iobase,DT2814_SIZE)<0){ + if(!request_region(iobase,DT2814_SIZE,"dt2814")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,DT2814_SIZE,"dt2814"); dev->iobase=iobase; dev->board_name = "dt2814"; diff --git a/comedi/drivers/dt2815.c b/comedi/drivers/dt2815.c index 72faec62..aafe13de 100644 --- a/comedi/drivers/dt2815.c +++ b/comedi/drivers/dt2815.c @@ -182,11 +182,10 @@ static int dt2815_attach(comedi_device * dev, comedi_devconfig * it) iobase = it->options[0]; printk("comedi%d: dt2815: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, DT2815_SIZE) < 0) { + if (!request_region(iobase, DT2815_SIZE, "dt2815")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, DT2815_SIZE, "dt2815"); dev->iobase = iobase; dev->board_name = "dt2815"; diff --git a/comedi/drivers/dt2817.c b/comedi/drivers/dt2817.c index 35421f98..9a86a62b 100644 --- a/comedi/drivers/dt2817.c +++ b/comedi/drivers/dt2817.c @@ -131,11 +131,10 @@ static int dt2817_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: dt2817: 0x%04x ",dev->minor,iobase); - if(check_region(iobase,DT2817_SIZE)<0){ + if(!request_region(iobase,DT2817_SIZE,"dt2817")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,DT2817_SIZE,"dt2817"); dev->iobase = iobase; dev->board_name="dt2817"; diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index 01e179d4..4ce4fbdf 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -1218,11 +1218,10 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) if(!iobase)iobase = 0x240; printk("comedi%d: dt282x: 0x%04x", dev->minor, iobase); - if (check_region(iobase, DT2821_SIZE) < 0) { + if (!request_region(iobase, DT2821_SIZE, "dt282x")) { printk(" I/O port conflict\n"); return -EBUSY; } - request_region(iobase, DT2821_SIZE, "dt282x"); dev->iobase = iobase; outw(DT2821_BDINIT, dev->iobase + DT2821_SUPCSR); diff --git a/comedi/drivers/fl512.c b/comedi/drivers/fl512.c index c2957f2e..fc42a641 100644 --- a/comedi/drivers/fl512.c +++ b/comedi/drivers/fl512.c @@ -141,11 +141,10 @@ static int fl512_attach(comedi_device *dev,comedi_devconfig *it) iobase = it->options[0]; printk("comedi:%d fl512: 0x%04x",dev->minor,iobase); - if (check_region(iobase, FL512_SIZE) < 0) { + if (!request_region(iobase, FL512_SIZE, "fl512")) { printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase, FL512_SIZE, "fl512"); dev->iobase = iobase; dev->board_name = "fl512"; if(alloc_private(dev,sizeof(fl512_private)) < 0) diff --git a/comedi/drivers/multiq3.c b/comedi/drivers/multiq3.c index 83257a58..69175099 100644 --- a/comedi/drivers/multiq3.c +++ b/comedi/drivers/multiq3.c @@ -238,12 +238,11 @@ static int multiq3_attach(comedi_device * dev, comedi_devconfig * it) iobase = it->options[0]; printk("comedi%d: multiq3: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, MULTIQ3_SIZE) < 0) { + if (!request_region(iobase, MULTIQ3_SIZE, "multiq3")) { printk("comedi%d: I/O port conflict\n", dev->minor); return -EIO; } - request_region(iobase, MULTIQ3_SIZE, "multiq3"); dev->iobase = iobase; irq = it->options[1]; diff --git a/comedi/drivers/ni_at_a2150.c b/comedi/drivers/ni_at_a2150.c index 77559c1c..cf421d55 100644 --- a/comedi/drivers/ni_at_a2150.c +++ b/comedi/drivers/ni_at_a2150.c @@ -365,12 +365,11 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) } /* check if io addresses are available */ - if(check_region(iobase, A2150_SIZE) < 0) + if(!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) { printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase, A2150_SIZE, driver_a2150.driver_name); dev->iobase = iobase; /* grab our IRQ */ diff --git a/comedi/drivers/ni_at_ao.c b/comedi/drivers/ni_at_ao.c index 5f0e57d8..0e084ee2 100644 --- a/comedi/drivers/ni_at_ao.c +++ b/comedi/drivers/ni_at_ao.c @@ -216,11 +216,10 @@ static int atao_attach(comedi_device *dev,comedi_devconfig *it) printk("comedi%d: ni_at_ao: 0x%04lx",dev->minor,iobase); - if(check_region(iobase, ATAO_SIZE) < 0){ + if(!request_region(iobase, ATAO_SIZE, "ni_at_ao")){ printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase, ATAO_SIZE, "ni_at_ao"); dev->iobase = iobase; //dev->board_ptr = atao_probe(dev); diff --git a/comedi/drivers/ni_atmio.c b/comedi/drivers/ni_atmio.c index 1ac604bd..5d545b07 100644 --- a/comedi/drivers/ni_atmio.c +++ b/comedi/drivers/ni_atmio.c @@ -434,11 +434,10 @@ static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it) /* reserve our I/O region */ printk("comedi%d: ni_atmio: 0x%04x",dev->minor,iobase); - if(check_region(iobase,NI_SIZE)<0){ + if(!request_region(iobase,NI_SIZE,"ni_atmio")){ printk(" I/O port conflict\n"); return -EIO; } - request_region(iobase,NI_SIZE,"ni_atmio"); dev->iobase=iobase; diff --git a/comedi/drivers/ni_atmio16d.c b/comedi/drivers/ni_atmio16d.c index 6bb04340..0dd3fc95 100644 --- a/comedi/drivers/ni_atmio16d.c +++ b/comedi/drivers/ni_atmio16d.c @@ -706,11 +706,10 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) /* make sure the address range is free and allocate it */ iobase = it->options[0]; printk("comedi%d: atmio16d: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, ATMIO16D_SIZE) < 0) { + if (!request_region(iobase, ATMIO16D_SIZE, "ni_atmio16d")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, ATMIO16D_SIZE, "ni_atmio16d"); dev->iobase = iobase; diff --git a/comedi/drivers/ni_labpc.c b/comedi/drivers/ni_labpc.c index 9b568024..69556267 100644 --- a/comedi/drivers/ni_labpc.c +++ b/comedi/drivers/ni_labpc.c @@ -494,12 +494,11 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, if(thisboard->bustype == isa_bustype) { /* check if io addresses are available */ - if(check_region(iobase, LABPC_SIZE) < 0) + if(!request_region(iobase, LABPC_SIZE, driver_labpc.driver_name)) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, LABPC_SIZE, driver_labpc.driver_name); } dev->iobase = iobase; diff --git a/comedi/drivers/pcl711.c b/comedi/drivers/pcl711.c index a8e91316..6c05d029 100644 --- a/comedi/drivers/pcl711.c +++ b/comedi/drivers/pcl711.c @@ -499,11 +499,10 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) iobase = it->options[0]; printk("comedi%d: pcl711: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, PCL711_SIZE) < 0) { + if (!request_region(iobase, PCL711_SIZE, "pcl711")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, PCL711_SIZE, "pcl711"); dev->iobase = iobase; /* there should be a sanity check here */ diff --git a/comedi/drivers/pcl724.c b/comedi/drivers/pcl724.c index 522f0178..28bf8d61 100644 --- a/comedi/drivers/pcl724.c +++ b/comedi/drivers/pcl724.c @@ -133,12 +133,11 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) iorange=PCL722_96_SIZE; // PCL-724 in 96 DIO configuration printk("comedi%d: pcl724: board=%s, 0x%03x ",dev->minor, this_board->name,iobase); - if(check_region(iobase,iorange)<0){ + if(!request_region(iobase, iorange, "pcl724")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, iorange, "pcl724"); dev->iobase=iobase; dev->board_name = this_board->name; diff --git a/comedi/drivers/pcl725.c b/comedi/drivers/pcl725.c index af864e76..a9d29b3e 100644 --- a/comedi/drivers/pcl725.c +++ b/comedi/drivers/pcl725.c @@ -64,11 +64,10 @@ static int pcl725_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: pcl725: 0x%04x ",dev->minor,iobase); - if(check_region(iobase,PCL725_SIZE)<0){ + if(!request_region(iobase,PCL725_SIZE,"pcl725")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,PCL725_SIZE,"pcl725"); dev->board_name="pcl725"; dev->iobase=iobase; dev->irq=0; diff --git a/comedi/drivers/pcl726.c b/comedi/drivers/pcl726.c index 1f1bfadc..2f15431e 100644 --- a/comedi/drivers/pcl726.c +++ b/comedi/drivers/pcl726.c @@ -245,12 +245,11 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; iorange=this_board->io_range; printk("comedi%d: pcl726: board=%s, 0x%03x ",dev->minor,this_board->name,iobase); - if(check_region(iobase,iorange)<0){ + if(!request_region(iobase, iorange, "pcl726")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, iorange, "pcl726"); dev->iobase=iobase; dev->board_name = this_board->name; diff --git a/comedi/drivers/pcl730.c b/comedi/drivers/pcl730.c index 70c3f5e2..797213ea 100644 --- a/comedi/drivers/pcl730.c +++ b/comedi/drivers/pcl730.c @@ -95,13 +95,11 @@ static int pcl730_attach(comedi_device *dev,comedi_devconfig *it) iorange=this_board->io_range; printk("comedi%d: pcl730: board=%s 0x%04x ", dev->minor, this_board->name, iobase); - if( check_region(iobase, iorange) < 0 ) - { + if( !request_region(iobase, iorange, "pcl730") ) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, iorange, "pcl730"); - dev->board_name=this_board->name; + dev->board_name=this_board->name; dev->iobase=iobase; dev->irq=0; diff --git a/comedi/drivers/pcl812.c b/comedi/drivers/pcl812.c index 88bf4525..3877404b 100644 --- a/comedi/drivers/pcl812.c +++ b/comedi/drivers/pcl812.c @@ -1183,11 +1183,10 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) printk("comedi%d: pcl812: board=%s, ioport=0x%03x", dev->minor, this_board->name, iobase); - if (check_region(iobase, this_board->io_range) < 0) { + if (!request_region(iobase, this_board->io_range, "pcl812")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, this_board->io_range, "pcl812"); dev->iobase = iobase; if ((ret = alloc_private(dev, sizeof(pcl812_private))) < 0) { diff --git a/comedi/drivers/pcl816.c b/comedi/drivers/pcl816.c index 621a8c45..276e9553 100644 --- a/comedi/drivers/pcl816.c +++ b/comedi/drivers/pcl816.c @@ -1024,12 +1024,11 @@ pcl816_attach (comedi_device * dev, comedi_devconfig * it) printk("comedi%d: pcl816: board=%s, ioport=0x%03x", dev->minor, this_board->name, iobase); - if (check_region (iobase, this_board->io_range) < 0) { + if (!request_region (iobase, this_board->io_range, "pcl816")) { rt_printk ("I/O port conflict\n"); return -EIO; } - request_region (iobase, this_board->io_range, "pcl816"); dev->iobase = iobase; if (pcl816_check (iobase)) { @@ -1084,9 +1083,8 @@ pcl816_attach (comedi_device * dev, comedi_devconfig * it) { // we want to use DMA if (RTC_lock == 0) { - if (check_region (RTC_PORT (0), RTC_IO_EXTENT) < 0) + if (!request_region (RTC_PORT (0), RTC_IO_EXTENT, "pcl816 (RTC)")) goto no_rtc; - request_region (RTC_PORT (0), RTC_IO_EXTENT, "pcl816 (RTC)"); } devpriv->rtc_iobase = RTC_PORT (0); devpriv->rtc_iosize = RTC_IO_EXTENT; diff --git a/comedi/drivers/pcl818.c b/comedi/drivers/pcl818.c index be2a9b40..6c211801 100644 --- a/comedi/drivers/pcl818.c +++ b/comedi/drivers/pcl818.c @@ -1597,12 +1597,11 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) devpriv->io_range=PCLx1xFIFO_RANGE; devpriv->usefifo = 1; } - if (check_region(iobase, this_board->io_range) < 0) { + if (!request_region(iobase, devpriv->io_range, "pcl818")) { rt_printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, devpriv->io_range, "pcl818"); dev->iobase=iobase; if (pcl818_check(iobase)) { @@ -1642,8 +1641,8 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) devpriv->dma_rtc=0; if (it->options[2]>0) { // we want to use DMA if (RTC_lock==0) { - if (check_region(RTC_PORT(0), RTC_IO_EXTENT) < 0) goto no_rtc; - request_region(RTC_PORT(0), RTC_IO_EXTENT, "pcl818 (RTC)"); + if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, "pcl818 (RTC)")) + goto no_rtc; } devpriv->rtc_iobase=RTC_PORT(0); devpriv->rtc_iosize=RTC_IO_EXTENT; diff --git a/comedi/drivers/pcm3730.c b/comedi/drivers/pcm3730.c index 34be1f5c..bbe75eb3 100644 --- a/comedi/drivers/pcm3730.c +++ b/comedi/drivers/pcm3730.c @@ -69,11 +69,10 @@ static int pcm3730_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: pcm3730: 0x%04x ",dev->minor,iobase); - if(check_region(iobase,PCM3730_SIZE)<0){ + if(!request_region(iobase,PCM3730_SIZE,"pcm3730")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,PCM3730_SIZE,"pcm3730"); dev->iobase=iobase; dev->board_name="pcm3730"; dev->iobase=dev->iobase; diff --git a/comedi/drivers/pcmad.c b/comedi/drivers/pcmad.c index 8b5c99b0..509f4f15 100644 --- a/comedi/drivers/pcmad.c +++ b/comedi/drivers/pcmad.c @@ -135,11 +135,10 @@ static int pcmad_attach(comedi_device *dev,comedi_devconfig *it) iobase=it->options[0]; printk("comedi%d: pcmad: 0x%04x ",dev->minor,iobase); - if(check_region(iobase,PCMAD_SIZE)<0){ + if(!request_region(iobase,PCMAD_SIZE,"pcmad")){ printk("I/O port conflict\n"); return -EIO; } - request_region(iobase,PCMAD_SIZE,"pcmad"); dev->iobase=iobase; if((ret=alloc_subdevices(dev, 1))<0) diff --git a/comedi/drivers/poc.c b/comedi/drivers/poc.c index 6dbeb823..8dc2dd1b 100644 --- a/comedi/drivers/poc.c +++ b/comedi/drivers/poc.c @@ -127,13 +127,12 @@ static int poc_attach(comedi_device *dev, comedi_devconfig *it) iosize = this_board->iosize; /* check if io addresses are available */ - if(check_region(iobase, iosize) < 0) + if(!request_region(iobase, iosize, "dac02")) { printk("I/O port conflict: failed to allocate ports 0x%x to 0x%x\n", iobase, iobase + iosize - 1); return -EIO; } - request_region(iobase, iosize, "dac02"); dev->iobase = iobase; if(alloc_subdevices(dev, 1) < 0) diff --git a/comedi/drivers/rti800.c b/comedi/drivers/rti800.c index c0512cd8..f15fa47b 100644 --- a/comedi/drivers/rti800.c +++ b/comedi/drivers/rti800.c @@ -302,11 +302,10 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) iobase = it->options[0]; printk("comedi%d: rti800: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, RTI800_SIZE) < 0) { + if (!request_region(iobase, RTI800_SIZE, "rti800")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, RTI800_SIZE, "rti800"); dev->iobase = iobase; #ifdef DEBUG diff --git a/comedi/drivers/rti802.c b/comedi/drivers/rti802.c index f5a50573..3b9612b0 100644 --- a/comedi/drivers/rti802.c +++ b/comedi/drivers/rti802.c @@ -105,11 +105,10 @@ static int rti802_attach(comedi_device * dev, comedi_devconfig * it) iobase = it->options[0]; printk("comedi%d: rti802: 0x%04x ", dev->minor, iobase); - if (check_region(iobase, RTI802_SIZE) < 0) { + if (!request_region(iobase, RTI802_SIZE, "rti802")) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, RTI802_SIZE, "rti802"); dev->iobase = iobase; dev->board_name = "rti802"; diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 1b59cc59..1755fe3a 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -15,5 +15,30 @@ #include_next +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,11) + +/* 'struct resource' not defined. Define a dummy version. */ +struct resource { + int dummy; +}; + +/* Define a compatible version of request_region that returns a pointer + * to a non-NULL value on success. */ +static inline struct resource *compat__request_region(unsigned long from, + unsigned long extent, const char *name) +{ + if (check_region(from, extent) < 0) { + return (struct resource *)0; + } + request_region(from, extent, name); + return ((struct resource *)0 + 1); /* Should be non-NULL */ +} + +/* Replace existing request_region macro/function. */ +#undef request_region +#define request_region(f,e,n) compat__request_region(f,e,n) + +#endif + #endif // _COMPAT_IOPORT_H diff --git a/include/linux/pci.h b/include/linux/pci.h index e295c534..ea1f4194 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -103,26 +103,26 @@ static inline int pci_request_regions(struct pci_dev *dev, char *name) if(dev->base_address[i]) { if(dev->base_address[i] & PCI_BASE_ADDRESS_SPACE_IO) - retval = check_region(pci_resource_start(dev, i), - fake_length); - if( retval ) - break; + if(!request_region(pci_resource_start(dev, i), + fake_length, name)) + { + retval = -EBUSY; + break; + } } } - if(retval) return retval; - - for(i = 0; i < max_num_base_addr; i++) + if(retval) { - if(dev->base_address[i]) + while(--i >= 0) { if(dev->base_address[i] & PCI_BASE_ADDRESS_SPACE_IO) - request_region(pci_resource_start(dev, i), - fake_length, name); + release_region(pci_resource_start(dev, i), + fake_length); } } - return 0; + return retval; } static inline void pci_release_regions(struct pci_dev *dev)