From: Frank Mori Hess Date: Sat, 15 Feb 2003 18:35:46 +0000 (+0000) Subject: Changed prototype of alloc_subdevices() so it doesn't require dev->n_subdevices X-Git-Tag: r0_7_67x~105 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=297f96a20024b6962b63901c3f1f3b0f71e8a14c;p=comedi.git Changed prototype of alloc_subdevices() so it doesn't require dev->n_subdevices to be set prior to being called. Fixed 8255 cleanup in ni_daq_dio24.c. Comedi sure has a lot of drivers these days! --- diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index 67941006..4d7354c0 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -373,9 +373,8 @@ static int dev_8255_attach(comedi_device *dev,comedi_devconfig *it) printk(" no devices specified\n"); return -EINVAL; } - dev->n_subdevices=i; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, i))<0) return ret; for(i=0;in_subdevices;i++){ diff --git a/comedi/drivers/adl_pci9111.c b/comedi/drivers/adl_pci9111.c index 12f9e1c2..31da8561 100644 --- a/comedi/drivers/adl_pci9111.c +++ b/comedi/drivers/adl_pci9111.c @@ -1341,9 +1341,8 @@ found: // // TODO: Add external multiplexer setup (according to option[2]). // - - dev->n_subdevices = 4; - if((error=alloc_subdevices(dev))<0) + + if((error=alloc_subdevices(dev, 4))<0) return error; subdevice = dev->subdevices + 0; diff --git a/comedi/drivers/adl_pci9118.c b/comedi/drivers/adl_pci9118.c index 046e3997..f8d8cad4 100644 --- a/comedi/drivers/adl_pci9118.c +++ b/comedi/drivers/adl_pci9118.c @@ -2088,8 +2088,7 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) pci_read_config_word(devpriv->pcidev, PCI_COMMAND, &u16w); pci_write_config_word(devpriv->pcidev, PCI_COMMAND, u16w|64); // Enable parity check for parity error - dev->n_subdevices = 4; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) return ret; s = dev->subdevices + 0; diff --git a/comedi/drivers/adv_pci1710.c b/comedi/drivers/adv_pci1710.c index 45c64bdc..7419058a 100644 --- a/comedi/drivers/adv_pci1710.c +++ b/comedi/drivers/adv_pci1710.c @@ -1117,12 +1117,12 @@ static int pci1710_reset(comedi_device *dev) static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; - int ret,subdev; + int ret,subdev,n_subdevices; unsigned short io_addr[5],master,irq; struct pcilst_struct *card=NULL; unsigned int iobase; unsigned char pci_bus,pci_slot,pci_func; - + if (!pci_list_builded) { pci_card_list_init(PCI_VENDOR_ID_ADVANTECH, #ifdef PCI171X_EXTDEBUG @@ -1137,20 +1137,20 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) rt_printk("comedi%d: adv_pci1710: board=%s",dev->minor,this_board->name); /* this call pci_enable_device() */ - if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ADVANTECH, this_board->device_id, it->options[0], it->options[1], 0))==NULL) + if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ADVANTECH, this_board->device_id, it->options[0], it->options[1], 0))==NULL) return -EIO; - + if ((pci_card_data(card,&pci_bus,&pci_slot,&pci_func, &io_addr[0],&irq,&master))<0) { pci_card_free(card); rt_printk(" - Can't get configuration data!\n"); return -EIO; } - + iobase=io_addr[2]; - + 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) { pci_card_free(card); rt_printk("I/O port conflict\n"); @@ -1159,7 +1159,7 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) request_region(iobase, this_board->iorange, "Advantech PCI-1710"); dev->iobase=iobase; - + dev->board_name = this_board->name; if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) { @@ -1167,14 +1167,14 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) pci_card_free(card); return -ENOMEM; } - - dev->n_subdevices = 0; - if (this_board->n_aichan) dev->n_subdevices++; - if (this_board->n_aochan) dev->n_subdevices++; - if (this_board->n_dichan) dev->n_subdevices++; - if (this_board->n_dochan) dev->n_subdevices++; - - if((ret=alloc_subdevices(dev))<0) { + + n_subdevices = 0; + if (this_board->n_aichan) n_subdevices++; + if (this_board->n_aochan) n_subdevices++; + if (this_board->n_dichan) n_subdevices++; + if (this_board->n_dochan) n_subdevices++; + + if((ret=alloc_subdevices(dev, n_subdevices))<0) { release_region(dev->iobase, this_board->iorange); pci_card_free(card); return ret; diff --git a/comedi/drivers/amplc_pc236.c b/comedi/drivers/amplc_pc236.c index 4277ce2a..6706e712 100644 --- a/comedi/drivers/amplc_pc236.c +++ b/comedi/drivers/amplc_pc236.c @@ -274,11 +274,9 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices = 2; - if ((ret=alloc_subdevices(dev)) < 0) { + if ((ret=alloc_subdevices(dev, 2)) < 0) { printk("out of memory!\n"); return ret; } diff --git a/comedi/drivers/amplc_pc263.c b/comedi/drivers/amplc_pc263.c index cfe46a7b..d83cf77c 100644 --- a/comedi/drivers/amplc_pc263.c +++ b/comedi/drivers/amplc_pc263.c @@ -236,11 +236,9 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices = 1; - if ((ret=alloc_subdevices(dev)) < 0) { + if ((ret=alloc_subdevices(dev, 1)) < 0) { printk("out of memory!\n"); return -ENOMEM; } diff --git a/comedi/drivers/amplc_pci230.c b/comedi/drivers/amplc_pci230.c index f3ba44a4..013e11af 100644 --- a/comedi/drivers/amplc_pci230.c +++ b/comedi/drivers/amplc_pci230.c @@ -370,11 +370,9 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices=4; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 4)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/cb_das16_cs.c b/comedi/drivers/cb_das16_cs.c index 8a974dca..371efab5 100644 --- a/comedi/drivers/cb_das16_cs.c +++ b/comedi/drivers/cb_das16_cs.c @@ -198,8 +198,7 @@ static int das16cs_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_private(dev,sizeof(das16cs_private))<0) return -ENOMEM; - dev->n_subdevices=4; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 4)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/cb_pcidas.c b/comedi/drivers/cb_pcidas.c index 508eb374..75ed737d 100644 --- a/comedi/drivers/cb_pcidas.c +++ b/comedi/drivers/cb_pcidas.c @@ -637,8 +637,7 @@ found: /* * Allocate the subdevice structures. */ - dev->n_subdevices = 7; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 7) < 0) return -ENOMEM; s = dev->subdevices + 0; diff --git a/comedi/drivers/cb_pcidas64.c b/comedi/drivers/cb_pcidas64.c index cb844236..71236f2a 100644 --- a/comedi/drivers/cb_pcidas64.c +++ b/comedi/drivers/cb_pcidas64.c @@ -1009,8 +1009,7 @@ static int setup_subdevices(comedi_device *dev) comedi_subdevice *s; unsigned long dio_8255_iobase; - dev->n_subdevices = 10; - if(alloc_subdevices(dev)<0) + if( alloc_subdevices( dev, 10 ) < 0 ) return -ENOMEM; s = dev->subdevices + 0; diff --git a/comedi/drivers/cb_pcidda.c b/comedi/drivers/cb_pcidda.c index e1cd3388..9b5f9047 100644 --- a/comedi/drivers/cb_pcidda.c +++ b/comedi/drivers/cb_pcidda.c @@ -364,8 +364,7 @@ found: /* * Allocate the subdevice structures. */ - dev->n_subdevices = 3; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices( dev, 3 ) < 0) return -ENOMEM; s = dev->subdevices + 0; diff --git a/comedi/drivers/cb_pcimdas.c b/comedi/drivers/cb_pcimdas.c index cc6ef29d..4bbe8bae 100644 --- a/comedi/drivers/cb_pcimdas.c +++ b/comedi/drivers/cb_pcimdas.c @@ -348,11 +348,9 @@ found: /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices=3; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 3)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/cb_pcimdda.c b/comedi/drivers/cb_pcimdda.c index f80ff2d3..54a7dc52 100644 --- a/comedi/drivers/cb_pcimdda.c +++ b/comedi/drivers/cb_pcimdda.c @@ -272,11 +272,9 @@ static int attach(comedi_device *dev,comedi_devconfig *it) /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices=2; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 2)<0) return -ENOMEM; s = dev->subdevices+0; diff --git a/comedi/drivers/comedi_parport.c b/comedi/drivers/comedi_parport.c index 8f963514..b8defbc9 100644 --- a/comedi/drivers/comedi_parport.c +++ b/comedi/drivers/comedi_parport.c @@ -309,8 +309,7 @@ static int parport_attach(comedi_device *dev,comedi_devconfig *it) } dev->board_name="parport"; - dev->n_subdevices=4; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) return ret; if((ret=alloc_private(dev,sizeof(parport_private)))<0) return ret; diff --git a/comedi/drivers/comedi_rt_timer.c b/comedi/drivers/comedi_rt_timer.c index 18acbdac..25eae43a 100644 --- a/comedi/drivers/comedi_rt_timer.c +++ b/comedi/drivers/comedi_rt_timer.c @@ -604,8 +604,7 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name="timer"; - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 1))<0) return ret; if((ret=alloc_private(dev,sizeof(timer_private)))<0) return ret; diff --git a/comedi/drivers/comedi_test.c b/comedi/drivers/comedi_test.c index cc5949e1..4eadb2fd 100644 --- a/comedi/drivers/comedi_test.c +++ b/comedi/drivers/comedi_test.c @@ -198,8 +198,7 @@ static int waveform_attach(comedi_device *dev,comedi_devconfig *it) devpriv->usec_period = period; printk("%i microvolt, %li microsecond waveform ", devpriv->uvolt_amplitude, devpriv->usec_period); - dev->n_subdevices = 1; - if(alloc_subdevices(dev) < 0) return -ENOMEM; + if(alloc_subdevices(dev, 1) < 0) return -ENOMEM; s = dev->subdevices + 0; dev->read_subdev = s; diff --git a/comedi/drivers/contec_pci_dio.c b/comedi/drivers/contec_pci_dio.c index 85362c88..4e6c8bc0 100644 --- a/comedi/drivers/contec_pci_dio.c +++ b/comedi/drivers/contec_pci_dio.c @@ -104,8 +104,7 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_private(dev,sizeof(contec_private))<0) return -ENOMEM; - dev->n_subdevices=2; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 2)<0) return -ENOMEM; pci_for_each_dev ( pcidev ) { diff --git a/comedi/drivers/daqboard2000.c b/comedi/drivers/daqboard2000.c index bb448204..133b8bb5 100644 --- a/comedi/drivers/daqboard2000.c +++ b/comedi/drivers/daqboard2000.c @@ -726,8 +726,7 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) result = alloc_private(dev,sizeof(daqboard2000_private)); if(result<0)goto out; - dev->n_subdevices = 3; - result = alloc_subdevices(dev); + result = alloc_subdevices(dev, 3); if(result<0)goto out; devpriv->plx = ioremap(pci_resource_start(card,0), DAQBOARD2000_PLX_SIZE); diff --git a/comedi/drivers/das08.c b/comedi/drivers/das08.c index b0f442d4..6bc999dc 100644 --- a/comedi/drivers/das08.c +++ b/comedi/drivers/das08.c @@ -818,8 +818,7 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = thisboard->name; - dev->n_subdevices=5; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 5))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/das16.c b/comedi/drivers/das16.c index 1e753f6c..f48d570d 100644 --- a/comedi/drivers/das16.c +++ b/comedi/drivers/das16.c @@ -1500,8 +1500,7 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) devpriv->timer_mode = timer_mode ? 1 : 0; } - dev->n_subdevices = 5; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 5))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/das16m1.c b/comedi/drivers/das16m1.c index c6fb4ce9..9e6a3a6e 100644 --- a/comedi/drivers/das16m1.c +++ b/comedi/drivers/das16m1.c @@ -681,8 +681,7 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) return -EINVAL; } - dev->n_subdevices = 4; - if((ret = alloc_subdevices(dev)) < 0) + if((ret = alloc_subdevices(dev, 4)) < 0) return ret; s = dev->subdevices + 0; diff --git a/comedi/drivers/das1800.c b/comedi/drivers/das1800.c index ca082d7c..b575c853 100644 --- a/comedi/drivers/das1800.c +++ b/comedi/drivers/das1800.c @@ -700,8 +700,7 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) return -ENOMEM; } - dev->n_subdevices = 4; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 4) < 0) return -ENOMEM; /* analog input subdevice */ diff --git a/comedi/drivers/das6402.c b/comedi/drivers/das6402.c index 90a20549..a66d7591 100644 --- a/comedi/drivers/das6402.c +++ b/comedi/drivers/das6402.c @@ -331,8 +331,7 @@ static int das6402_attach(comedi_device *dev,comedi_devconfig *it) if((ret=alloc_private(dev,sizeof(das6402_private)))<0) return ret; - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 1))<0) return ret; /* ai subdevice */ diff --git a/comedi/drivers/das800.c b/comedi/drivers/das800.c index d94c9458..9e9e6ddd 100644 --- a/comedi/drivers/das800.c +++ b/comedi/drivers/das800.c @@ -510,8 +510,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; - dev->n_subdevices = 3; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 3) < 0) return -ENOMEM; /* analog input subdevice */ diff --git a/comedi/drivers/dt2801.c b/comedi/drivers/dt2801.c index 9cef9222..5e517baf 100644 --- a/comedi/drivers/dt2801.c +++ b/comedi/drivers/dt2801.c @@ -520,9 +520,7 @@ havetype: n_ai_chans=probe_number_of_ai_chans(dev); printk(" (ai channels = %d)",n_ai_chans); - dev->n_subdevices=4; - - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) goto out; if((ret=alloc_private(dev,sizeof(dt2801_private)))<0) diff --git a/comedi/drivers/dt2811.c b/comedi/drivers/dt2811.c index 9fbd65c8..0c6d948f 100644 --- a/comedi/drivers/dt2811.c +++ b/comedi/drivers/dt2811.c @@ -359,8 +359,7 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) } #endif - dev->n_subdevices = 4; - if ((ret = alloc_subdevices(dev)) < 0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; if ((ret = alloc_private(dev, sizeof(dt2811_private))) < 0) return ret; diff --git a/comedi/drivers/dt2814.c b/comedi/drivers/dt2814.c index c9bc55d4..0b6ff7aa 100644 --- a/comedi/drivers/dt2814.c +++ b/comedi/drivers/dt2814.c @@ -289,9 +289,8 @@ static int dt2814_attach(comedi_device *dev,comedi_devconfig *it) }else{ printk("(probe returned multiple irqs--bad)\n"); } - - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + + if((ret=alloc_subdevices(dev, 1))<0) return ret; if((ret=alloc_private(dev,sizeof(dt2814_private)))<0) return ret; diff --git a/comedi/drivers/dt2815.c b/comedi/drivers/dt2815.c index c02ae551..254790fd 100644 --- a/comedi/drivers/dt2815.c +++ b/comedi/drivers/dt2815.c @@ -191,8 +191,7 @@ static int dt2815_attach(comedi_device * dev, comedi_devconfig * it) dev->iobase = iobase; dev->board_name = "dt2815"; - dev->n_subdevices = 1; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 1)<0) return -ENOMEM; if(alloc_private(dev,sizeof(dt2815_private))<0) return -ENOMEM; diff --git a/comedi/drivers/dt2817.c b/comedi/drivers/dt2817.c index a0a95613..35421f98 100644 --- a/comedi/drivers/dt2817.c +++ b/comedi/drivers/dt2817.c @@ -139,8 +139,7 @@ static int dt2817_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase = iobase; dev->board_name="dt2817"; - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 1))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index 5025933e..cf538324 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -1250,8 +1250,7 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) if(ret<0) return ret; - dev->n_subdevices = 3; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 3))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/dt3000.c b/comedi/drivers/dt3000.c index 8da75e07..04fb3799 100644 --- a/comedi/drivers/dt3000.c +++ b/comedi/drivers/dt3000.c @@ -781,8 +781,7 @@ static int dt3000_attach(comedi_device *dev,comedi_devconfig *it) } dev->irq = devpriv->pci_dev->irq; - dev->n_subdevices = 4; - if( (ret = alloc_subdevices(dev)) <0) + if( (ret = alloc_subdevices(dev, 4)) <0) return ret; s=dev->subdevices; diff --git a/comedi/drivers/fl512.c b/comedi/drivers/fl512.c index aa7a4748..136c8230 100644 --- a/comedi/drivers/fl512.c +++ b/comedi/drivers/fl512.c @@ -148,7 +148,6 @@ static int fl512_attach(comedi_device *dev,comedi_devconfig *it) request_region(iobase, FL512_SIZE, "fl512"); dev->iobase = iobase; dev->board_name = "fl512"; - dev->n_subdevices = 2; /* Analog in/out */ if(alloc_private(dev,sizeof(fl512_private)) < 0) return -ENOMEM; @@ -156,7 +155,7 @@ static int fl512_attach(comedi_device *dev,comedi_devconfig *it) printk("malloc ok\n"); #endif - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 2)<0) return -ENOMEM; /* diff --git a/comedi/drivers/icp_multi.c b/comedi/drivers/icp_multi.c index a0ad8dde..482b1f2c 100644 --- a/comedi/drivers/icp_multi.c +++ b/comedi/drivers/icp_multi.c @@ -844,12 +844,12 @@ static int icp_multi_reset(comedi_device *dev) static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; - int ret, subdev; + int ret, subdev, n_subdevices; unsigned short master,irq; struct pcilst_struct *card=NULL; unsigned long io_addr[5], iobase; unsigned char pci_bus, pci_slot, pci_func; - + printk("icp_multi EDBG: BGN: icp_multi_attach(...)\n"); // Alocate private data storage space @@ -872,13 +872,13 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ICP, this_board->device_id, it->options[0], it->options[1]))==NULL) return -EIO; - + if ((pci_card_data(card, &pci_bus, &pci_slot, &pci_func, &io_addr[0], &irq, &master))<0) { pci_card_free(card); printk(" - Can't get configuration data!\n"); return -EIO; } - + iobase=io_addr[2]; // if(check_mem_region(iobase, ICP_MULTI_SIZE)) @@ -891,7 +891,7 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) devpriv->phys_iobase = iobase; printk(", b:s:f=%d:%d:%d, io=0x%8lx \n", pci_bus, pci_slot, pci_func, iobase); - + devpriv->io_addr = ioremap(iobase, ICP_MULTI_SIZE); if (devpriv->io_addr == NULL) { @@ -907,14 +907,14 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = this_board->name; - dev->n_subdevices = 0; - if (this_board->n_aichan) dev->n_subdevices++; - if (this_board->n_aochan) dev->n_subdevices++; - if (this_board->n_dichan) dev->n_subdevices++; - if (this_board->n_dochan) dev->n_subdevices++; - if (this_board->n_ctrs) dev->n_subdevices++; - - if((ret=alloc_subdevices(dev))<0) { + n_subdevices = 0; + if (this_board->n_aichan) n_subdevices++; + if (this_board->n_aochan) n_subdevices++; + if (this_board->n_dichan) n_subdevices++; + if (this_board->n_dochan) n_subdevices++; + if (this_board->n_ctrs) n_subdevices++; + + if((ret=alloc_subdevices(dev, n_subdevices))<0) { pci_card_free(card); return ret; } diff --git a/comedi/drivers/ii_pci20kc.c b/comedi/drivers/ii_pci20kc.c index a5bb10de..63adcbe9 100644 --- a/comedi/drivers/ii_pci20kc.c +++ b/comedi/drivers/ii_pci20kc.c @@ -209,8 +209,7 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it) comedi_subdevice *s; pci20xxx_subdev_private *sdp; - dev->n_subdevices = 1+PCI20000_MODULES; - if ((ret = alloc_subdevices(dev)) < 0) + if ((ret = alloc_subdevices(dev, 1 + PCI20000_MODULES)) < 0) return ret; if ((ret = alloc_private(dev, sizeof(pci20xxx_private))) < 0) return ret; diff --git a/comedi/drivers/ke_counter.c b/comedi/drivers/ke_counter.c index 9d6c46cf..8aea37ee 100644 --- a/comedi/drivers/ke_counter.c +++ b/comedi/drivers/ke_counter.c @@ -181,8 +181,7 @@ found: dev->iobase = io_base & PCI_BASE_ADDRESS_IO_MASK; /* allocate the subdevice structures */ - dev->n_subdevices = 1; - if((error = alloc_subdevices(dev)) < 0) + if((error = alloc_subdevices(dev, 1)) < 0) { return error; } diff --git a/comedi/drivers/me_daq.c b/comedi/drivers/me_daq.c index d9c1a72e..4264d0c2 100644 --- a/comedi/drivers/me_daq.c +++ b/comedi/drivers/me_daq.c @@ -818,8 +818,7 @@ found: // device driver capabilities - dev->n_subdevices = 3; - if((error = alloc_subdevices(dev)) < 0) + if((error = alloc_subdevices(dev, 3)) < 0) return error; subdevice = dev->subdevices + 0; diff --git a/comedi/drivers/mpc8260cpm.c b/comedi/drivers/mpc8260cpm.c index b88bf567..2470295a 100644 --- a/comedi/drivers/mpc8260cpm.c +++ b/comedi/drivers/mpc8260cpm.c @@ -72,8 +72,7 @@ static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_private(dev,sizeof(mpc8260cpm_private))<0) return -ENOMEM; - dev->n_subdevices=4; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev,4)<0) return -ENOMEM; for(i=0;i<4;i++){ diff --git a/comedi/drivers/multiq3.c b/comedi/drivers/multiq3.c index 79925ffd..bceab4f2 100644 --- a/comedi/drivers/multiq3.c +++ b/comedi/drivers/multiq3.c @@ -250,8 +250,7 @@ static int multiq3_attach(comedi_device * dev, comedi_devconfig * it) printk("comedi%d: no irq\n", dev->minor); } dev->board_name = "multiq3"; - dev->n_subdevices = 5; - result = alloc_subdevices(dev); + result = alloc_subdevices(dev, 5); if(result<0)return result; result = alloc_private(dev,sizeof(struct multiq3_private)); diff --git a/comedi/drivers/ni_6527.c b/comedi/drivers/ni_6527.c index 76649d14..10766271 100644 --- a/comedi/drivers/ni_6527.c +++ b/comedi/drivers/ni_6527.c @@ -354,8 +354,7 @@ static int ni6527_attach(comedi_device *dev,comedi_devconfig *it) printk(" ID=0x%02x", readb(dev->iobase + ID_Register)); - dev->n_subdevices=2; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev,2))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/ni_670x.c b/comedi/drivers/ni_670x.c index 7ee82813..169dc318 100644 --- a/comedi/drivers/ni_670x.c +++ b/comedi/drivers/ni_670x.c @@ -157,9 +157,7 @@ static int ni_670x_attach(comedi_device *dev,comedi_devconfig *it) dev->irq=mite_irq(devpriv->mite); printk(" %s",dev->board_name); - dev->n_subdevices=2; - - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 2)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/ni_at_a2150.c b/comedi/drivers/ni_at_a2150.c index d97fd126..296b1c00 100644 --- a/comedi/drivers/ni_at_a2150.c +++ b/comedi/drivers/ni_at_a2150.c @@ -418,8 +418,7 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) dev->board_ptr = a2150_boards + a2150_probe(dev); dev->board_name = thisboard->name; - dev->n_subdevices = 1; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 1) < 0) return -ENOMEM; /* analog input subdevice */ diff --git a/comedi/drivers/ni_at_ao.c b/comedi/drivers/ni_at_ao.c index 711898c0..c8656f4e 100644 --- a/comedi/drivers/ni_at_ao.c +++ b/comedi/drivers/ni_at_ao.c @@ -224,8 +224,7 @@ static int atao_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_private(dev,sizeof(atao_private))<0) return -ENOMEM; - dev->n_subdevices=4; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 4)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/ni_atmio16d.c b/comedi/drivers/ni_atmio16d.c index 68df12d0..6723ff63 100644 --- a/comedi/drivers/ni_atmio16d.c +++ b/comedi/drivers/ni_atmio16d.c @@ -716,10 +716,7 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) /* board name */ dev->board_name = boardtype->name; - /* set number of subdevices */ - dev->n_subdevices=4; - - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) return ret; if((ret=alloc_private(dev,sizeof(atmio16d_private)))<0) return ret; diff --git a/comedi/drivers/ni_daq_dio24.c b/comedi/drivers/ni_daq_dio24.c index ae8d8b9e..cc6d0220 100644 --- a/comedi/drivers/ni_daq_dio24.c +++ b/comedi/drivers/ni_daq_dio24.c @@ -166,8 +166,7 @@ static int dio24_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; - dev->n_subdevices = 2; // Antes era 5 - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 1) < 0) return -ENOMEM; /* 8255 dio */ @@ -182,7 +181,7 @@ static int dio24_detach(comedi_device *dev) printk("comedi%d: ni_daq_dio24: remove\n", dev->minor); if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 2); + subdev_8255_cleanup(dev,dev->subdevices + 0); if(thisboard->bustype != pcmcia_bustype && dev->iobase) diff --git a/comedi/drivers/ni_labpc.c b/comedi/drivers/ni_labpc.c index 873c99ed..10037fbd 100644 --- a/comedi/drivers/ni_labpc.c +++ b/comedi/drivers/ni_labpc.c @@ -663,8 +663,7 @@ static int labpc_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; - dev->n_subdevices = 5; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 5) < 0) return -ENOMEM; /* analog input subdevice */ diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index 8b597a1f..3be67445 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -2367,9 +2367,7 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) comedi_subdevice *s; int bits; - dev->n_subdevices=8; - - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 8)<0) return -ENOMEM; /* analog input subdevice */ diff --git a/comedi/drivers/ni_pcidio.c b/comedi/drivers/ni_pcidio.c index 5ed0d3a8..582c8466 100644 --- a/comedi/drivers/ni_pcidio.c +++ b/comedi/drivers/ni_pcidio.c @@ -923,12 +923,13 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) comedi_subdevice *s; int i; int ret; - + int n_subdevices; + printk("comedi%d: nidio:",dev->minor); if((ret=alloc_private(dev,sizeof(nidio96_private)))<0) return ret; - + ret=nidio_find_device(dev,it->options[0],it->options[1]); if(ret<0)return ret; @@ -945,11 +946,11 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) printk(" %s",dev->board_name); if(!this_board->is_diodaq){ - dev->n_subdevices=this_board->n_8255; + n_subdevices=this_board->n_8255; }else{ - dev->n_subdevices=1; + n_subdevices=1; } - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, n_subdevices))<0) return ret; if(!this_board->is_diodaq){ diff --git a/comedi/drivers/pcl711.c b/comedi/drivers/pcl711.c index baca557f..41943c9d 100644 --- a/comedi/drivers/pcl711.c +++ b/comedi/drivers/pcl711.c @@ -526,8 +526,7 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) } dev->irq = irq; - dev->n_subdevices = 4; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) return ret; if((ret=alloc_private(dev,sizeof(pcl711_private)))<0) return ret; diff --git a/comedi/drivers/pcl724.c b/comedi/drivers/pcl724.c index b28bc1ee..c7786659 100644 --- a/comedi/drivers/pcl724.c +++ b/comedi/drivers/pcl724.c @@ -125,8 +125,8 @@ static int subdev_8255mapped_cb(int dir,int port,int data,unsigned long iobase) static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) { int iobase,iorange; - int ret,i; - + int ret,i,n_subdevices; + iobase=it->options[0]; iorange=this_board->io_range; if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) @@ -137,10 +137,10 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) printk("I/O port conflict\n"); return -EIO; } - + request_region(iobase, iorange, "pcl724"); dev->iobase=iobase; - + dev->board_name = this_board->name; #ifdef PCL724_IRQ @@ -151,27 +151,27 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) if (((1<IRQbits)==0) { rt_printk(", IRQ %d is out of allowed range, DISABLING IT",irq); irq=0; /* Bad IRQ */ - } else { + } else { if (comedi_request_irq(irq, interrupt_pcl724, 0, "pcl724", dev)) { rt_printk(", unable to allocate IRQ %d, DISABLING IT", irq); irq=0; /* Can't use IRQ */ } else { rt_printk(", irq=%d", irq); - } - } + } + } } } dev->irq = irq; #endif - + printk("\n"); - dev->n_subdevices=this_board->numofports; + n_subdevices=this_board->numofports; if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) - dev->n_subdevices=4; // PCL-724 in 96 DIO configuration - - if((ret=alloc_subdevices(dev))<0) + n_subdevices=4; // PCL-724 in 96 DIO configuration + + if((ret=alloc_subdevices(dev, n_subdevices))<0) return ret; for(i=0;in_subdevices;i++){ diff --git a/comedi/drivers/pcl725.c b/comedi/drivers/pcl725.c index 3575aa96..af864e76 100644 --- a/comedi/drivers/pcl725.c +++ b/comedi/drivers/pcl725.c @@ -73,9 +73,7 @@ static int pcl725_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase=iobase; dev->irq=0; - dev->n_subdevices=2; - - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 2)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/pcl726.c b/comedi/drivers/pcl726.c index 6bb7811a..1f1bfadc 100644 --- a/comedi/drivers/pcl726.c +++ b/comedi/drivers/pcl726.c @@ -288,9 +288,7 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) printk("\n"); - dev->n_subdevices=3; - - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 3))<0) return ret; s=dev->subdevices+0; diff --git a/comedi/drivers/pcl812.c b/comedi/drivers/pcl812.c index d6391f17..570b7c44 100644 --- a/comedi/drivers/pcl812.c +++ b/comedi/drivers/pcl812.c @@ -1165,7 +1165,7 @@ static void pcl812_reset(comedi_device * dev) } -/* +/* ============================================================================== */ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) @@ -1176,6 +1176,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) int dma; unsigned long pages; comedi_subdevice *s; + int n_subdevices; iobase = it->options[0]; printk("comedi%d: pcl812: board=%s, ioport=0x%03x", dev->minor, @@ -1255,14 +1256,13 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) } no_dma: - dev->n_subdevices=0; - - if (this_board->n_aichan > 0) dev->n_subdevices++; - if (this_board->n_aochan > 0) dev->n_subdevices++; - if (this_board->n_dichan > 0) dev->n_subdevices++; - if (this_board->n_dochan > 0) dev->n_subdevices++; + n_subdevices=0; + if (this_board->n_aichan > 0) n_subdevices++; + if (this_board->n_aochan > 0) n_subdevices++; + if (this_board->n_dichan > 0) n_subdevices++; + if (this_board->n_dochan > 0) n_subdevices++; - if ((ret = alloc_subdevices(dev)) < 0) { + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) { free_resources(dev); return ret; } diff --git a/comedi/drivers/pcl816.c b/comedi/drivers/pcl816.c index 66312c86..5a7d83f5 100644 --- a/comedi/drivers/pcl816.c +++ b/comedi/drivers/pcl816.c @@ -1152,8 +1152,7 @@ no_dma: if (this_board->n_dochan > 0) subdevs[3] = COMEDI_SUBD_DO; */ - dev->n_subdevices = 1; - if ((ret = alloc_subdevices (dev)) < 0) + if ((ret = alloc_subdevices (dev, 1)) < 0) return ret; s = dev->subdevices + 0; diff --git a/comedi/drivers/pcl818.c b/comedi/drivers/pcl818.c index 8ce26613..298965cd 100644 --- a/comedi/drivers/pcl818.c +++ b/comedi/drivers/pcl818.c @@ -1490,8 +1490,7 @@ no_rtc: no_dma: - dev->n_subdevices = 4; - if((ret=alloc_subdevices(dev))<0) return ret; + if((ret=alloc_subdevices(dev, 4))<0) return ret; s = dev->subdevices + 0; if(!this_board->n_aichan_se){ diff --git a/comedi/drivers/pcm3730.c b/comedi/drivers/pcm3730.c index 9a037050..bde98e35 100644 --- a/comedi/drivers/pcm3730.c +++ b/comedi/drivers/pcm3730.c @@ -79,9 +79,7 @@ static int pcm3730_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase=dev->iobase; dev->irq=0; - dev->n_subdevices=6; - - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 6)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/pcmad.c b/comedi/drivers/pcmad.c index 2dfe3242..8b5c99b0 100644 --- a/comedi/drivers/pcmad.c +++ b/comedi/drivers/pcmad.c @@ -142,8 +142,7 @@ static int pcmad_attach(comedi_device *dev,comedi_devconfig *it) request_region(iobase,PCMAD_SIZE,"pcmad"); dev->iobase=iobase; - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 1))<0) return ret; if((ret=alloc_private(dev,sizeof(struct pcmad_priv_struct)))<0) return ret; diff --git a/comedi/drivers/poc.c b/comedi/drivers/poc.c index 3efd2dc0..3474eede 100644 --- a/comedi/drivers/poc.c +++ b/comedi/drivers/poc.c @@ -137,8 +137,7 @@ static int poc_attach(comedi_device *dev, comedi_devconfig *it) request_region(iobase, iosize, "dac02"); dev->iobase = iobase; - dev->n_subdevices = 1; - if(alloc_subdevices(dev) < 0) + if(alloc_subdevices(dev, 1) < 0) return -ENOMEM; if(alloc_private(dev,sizeof(lsampl_t)*this_board->n_chan) < 0) return -ENOMEM; diff --git a/comedi/drivers/quatech_daqp_cs.c b/comedi/drivers/quatech_daqp_cs.c index 4be6d06b..b757f94c 100644 --- a/comedi/drivers/quatech_daqp_cs.c +++ b/comedi/drivers/quatech_daqp_cs.c @@ -384,8 +384,7 @@ static int daqp_attach(comedi_device *dev, comedi_devconfig *it) return ret; devpriv->devnum = it->options[0]; - dev->n_subdevices=1; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 1))<0) return ret; printk("comedi%d: attaching daqp%d (io 0x%04x)\n", diff --git a/comedi/drivers/rtd520.c b/comedi/drivers/rtd520.c index 26ff9f3e..d91c8370 100644 --- a/comedi/drivers/rtd520.c +++ b/comedi/drivers/rtd520.c @@ -863,11 +863,9 @@ static int rtd_attach ( /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices=4; - if (alloc_subdevices(dev)<0) { + if (alloc_subdevices(dev, 4)<0) { return -ENOMEM; } diff --git a/comedi/drivers/rti800.c b/comedi/drivers/rti800.c index a00bf534..c102fed8 100644 --- a/comedi/drivers/rti800.c +++ b/comedi/drivers/rti800.c @@ -328,8 +328,7 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) dev->board_name = this_board->name; - dev->n_subdevices=4; - if((ret=alloc_subdevices(dev))<0) + if((ret=alloc_subdevices(dev, 4))<0) return ret; if((ret=alloc_private(dev,sizeof(rti800_private)))<0) return ret; diff --git a/comedi/drivers/rti802.c b/comedi/drivers/rti802.c index 34fd615c..f5a50573 100644 --- a/comedi/drivers/rti802.c +++ b/comedi/drivers/rti802.c @@ -114,8 +114,7 @@ static int rti802_attach(comedi_device * dev, comedi_devconfig * it) dev->board_name = "rti802"; - dev->n_subdevices = 1; - if(alloc_subdevices(dev)<0 || alloc_private(dev,sizeof(rti802_private))){ + if(alloc_subdevices(dev, 1)<0 || alloc_private(dev,sizeof(rti802_private))){ return -ENOMEM; } diff --git a/comedi/drivers/serial2002.c b/comedi/drivers/serial2002.c index 92aa7d9c..b6933693 100644 --- a/comedi/drivers/serial2002.c +++ b/comedi/drivers/serial2002.c @@ -549,8 +549,7 @@ static int serial2002_attach(comedi_device *dev,comedi_devconfig *it) devpriv->speed = it->options[1]; printk("/dev/ttyS%d @ %d\n", devpriv->port, devpriv->speed); - dev->n_subdevices=4; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 4)<0) return -ENOMEM; /* digital input subdevice */ diff --git a/comedi/drivers/skel.c b/comedi/drivers/skel.c index 517eb4ca..63141c0a 100644 --- a/comedi/drivers/skel.c +++ b/comedi/drivers/skel.c @@ -226,11 +226,9 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) /* * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. + * convenient macro defined in comedidev.h. */ - dev->n_subdevices=3; - if(alloc_subdevices(dev)<0) + if(alloc_subdevices(dev, 3)<0) return -ENOMEM; s=dev->subdevices+0; diff --git a/comedi/drivers/ssv_dnp.c b/comedi/drivers/ssv_dnp.c index 5a155d49..f1ee19f3 100644 --- a/comedi/drivers/ssv_dnp.c +++ b/comedi/drivers/ssv_dnp.c @@ -146,11 +146,9 @@ static int dnp_attach(comedi_device *dev,comedi_devconfig *it) if(alloc_private(dev,sizeof(dnp_private_data))<0) return -ENOMEM; /* Allocate the subdevice structures. alloc_subdevice() is a convenient */ - /* macro defined in comedidev.h. It relies on n_subdevices being set */ - /* correctly. */ + /* macro defined in comedidev.h. */ - dev->n_subdevices=1; - if(alloc_subdevices(dev)<0) return -ENOMEM; + if(alloc_subdevices(dev, 1)<0) return -ENOMEM; s=dev->subdevices+0; /* digital i/o subdevice */ diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index e0e45289..038d0486 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -316,10 +316,11 @@ struct comedi_lrange_struct{ /* some silly little inline functions */ -static inline int alloc_subdevices(comedi_device *dev) +static inline int alloc_subdevices(comedi_device *dev, unsigned int num_subdevices) { - int size=sizeof(comedi_subdevice)*dev->n_subdevices; + int size=sizeof(comedi_subdevice)*num_subdevices; + dev->n_subdevices = num_subdevices; dev->subdevices=kmalloc(size,GFP_KERNEL); if(!dev->subdevices) return -ENOMEM;