dect
/
linux-2.6
Archived
13
0
Fork 0

Staging: comedi: make use of ARRAY_SIZE macro

Replace instances of computing number of elements in an array with
sizeof(foo)/sizeof(struct footype) with the ARRAY_SIZE macro.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Bill Pemberton 2009-04-23 15:54:56 -04:00 committed by Greg Kroah-Hartman
parent b4918808de
commit 8629efa4cb
40 changed files with 43 additions and 67 deletions

View File

@ -853,7 +853,8 @@ int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name)
/* pci slot */
options[1] = PCI_SLOT(pcidev->devfn);
return comedi_auto_config(&pcidev->dev, board_name, options, sizeof(options) / sizeof(options[0]));
return comedi_auto_config(&pcidev->dev, board_name,
options, ARRAY_SIZE(options));
}
void comedi_pci_auto_unconfig(struct pci_dev *pcidev)

View File

@ -110,9 +110,6 @@ struct pci6208_private {
static int pci6208_attach(struct comedi_device *dev, struct comedi_devconfig *it);
static int pci6208_detach(struct comedi_device *dev);
#define pci6208_board_nbr \
(sizeof(pci6208_boards) / sizeof(struct pci6208_board))
static struct comedi_driver driver_pci6208 = {
.driver_name = PCI6208_DRIVER_NAME,
.module = THIS_MODULE,
@ -315,7 +312,7 @@ static int pci6208_find_device(struct comedi_device *dev, int bus, int slot)
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++) {
for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) {
if (pci6208_boards[i].dev_id == pci_dev->device) {
/* was a particular bus/slot requested? */
if ((bus != 0) || (slot != 0)) {

View File

@ -171,7 +171,7 @@ static struct comedi_driver driver_adq12b={
detach: adq12b_detach,
board_name: &adq12b_boards[0].name,
offset: sizeof(struct adq12b_board),
num_names: sizeof(adq12b_boards) / sizeof(struct adq12b_board),
num_names: ARRAY_SIZE(adq12b_boards),
};
static int adq12b_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data);

View File

@ -78,7 +78,7 @@ static struct comedi_driver driver_aio_iiro_16 = {
.detach = aio_iiro_16_detach,
.board_name = &aio_iiro_16_boards[0].name,
.offset = sizeof(struct aio_iiro_16_board),
.num_names = sizeof(aio_iiro_16_boards) / sizeof(struct aio_iiro_16_board),
.num_names = ARRAY_SIZE(aio_iiro_16_boards),
};
static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,

View File

@ -484,7 +484,7 @@ static struct comedi_driver driver_amplc_dio200 = {
.detach = dio200_detach,
.board_name = &dio200_boards[0].name,
.offset = sizeof(struct dio200_board),
.num_names = sizeof(dio200_boards) / sizeof(struct dio200_board),
.num_names = ARRAY_SIZE(dio200_boards),
};
#ifdef CONFIG_COMEDI_PCI

View File

@ -176,7 +176,7 @@ static struct comedi_driver driver_amplc_pc236 = {
.detach = pc236_detach,
.board_name = &pc236_boards[0].name,
.offset = sizeof(struct pc236_board),
.num_names = sizeof(pc236_boards) / sizeof(struct pc236_board),
.num_names = ARRAY_SIZE(pc236_boards),
};
#ifdef CONFIG_COMEDI_PCI

View File

@ -141,7 +141,7 @@ static struct comedi_driver driver_amplc_pc263 = {
.detach = pc263_detach,
.board_name = &pc263_boards[0].name,
.offset = sizeof(struct pc263_board),
.num_names = sizeof(pc263_boards) / sizeof(struct pc263_board),
.num_names = ARRAY_SIZE(pc263_boards),
};
static int pc263_request_region(unsigned minor, unsigned long from,

View File

@ -437,7 +437,7 @@ static struct comedi_driver driver_amplc_pci224 = {
.detach = pci224_detach,
.board_name = &pci224_boards[0].name,
.offset = sizeof(struct pci224_board),
.num_names = sizeof(pci224_boards) / sizeof(struct pci224_board),
.num_names = ARRAY_SIZE(pci224_boards),
};
COMEDI_PCI_INITCLEANUP(driver_amplc_pci224, pci224_pci_table);

View File

@ -612,7 +612,7 @@ static struct comedi_driver driver_amplc_pci230 = {
.detach = pci230_detach,
.board_name = &pci230_boards[0].name,
.offset = sizeof(pci230_boards[0]),
.num_names = sizeof(pci230_boards) / sizeof(pci230_boards[0]),
.num_names = ARRAY_SIZE(pci230_boards),
};
COMEDI_PCI_INITCLEANUP(driver_amplc_pci230, pci230_pci_table);

View File

@ -375,9 +375,6 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
},
};
/* Number of boards in cb_pcidas_boards */
#define N_BOARDS (sizeof(cb_pcidas_boards) / sizeof(struct cb_pcidas_board))
static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
{PCI_VENDOR_ID_CB, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{PCI_VENDOR_ID_CB, 0x000f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@ -536,7 +533,7 @@ static int cb_pcidas_attach(struct comedi_device *dev, struct comedi_devconfig *
if (pcidev->vendor != PCI_VENDOR_ID_CB)
continue;
/* loop through cards supported by this driver */
for (index = 0; index < N_BOARDS; index++) {
for (index = 0; index < ARRAY_SIZE(cb_pcidas_boards); index++) {
if (cb_pcidas_boards[index].device_id != pcidev->device)
continue;
/* was a particular bus/slot requested? */

View File

@ -1014,12 +1014,6 @@ static const struct pcidas64_board pcidas64_boards[] = {
#endif
};
/* Number of boards in cb_pcidas_boards */
static inline unsigned int num_boards(void)
{
return sizeof(pcidas64_boards) / sizeof(struct pcidas64_board);
}
static DEFINE_PCI_DEVICE_TABLE(pcidas64_pci_table) = {
{PCI_VENDOR_ID_COMPUTERBOARDS, 0x001d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{PCI_VENDOR_ID_COMPUTERBOARDS, 0x001e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@ -1702,7 +1696,7 @@ static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue;
/* loop through cards supported by this driver */
for (index = 0; index < num_boards(); index++) {
for (index = 0; index < ARRAY_SIZE(pcidas64_boards); index++) {
if (pcidas64_boards[index].device_id != pcidev->device)
continue;
/* was a particular bus/slot requested? */

View File

@ -204,7 +204,7 @@ static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
continue;
/* loop through cards supported by this driver */
for (index = 0;
index < sizeof pcidio_boards / sizeof(struct pcidio_board);
index < ARRAY_SIZE(pcidio_boards);
index++) {
if (pcidio_pci_table[index].device != pcidev->device)
continue;

View File

@ -135,8 +135,6 @@ static const struct board_struct boards[] = {
*/
#define thisboard ((const struct board_struct *)dev->board_ptr)
/* Number of boards in boards[] */
#define N_BOARDS (sizeof(boards) / sizeof(struct board_struct))
#define REG_SZ (thisboard->reg_sz)
#define REGS_BADRINDEX (thisboard->regs_badrindex)
@ -439,7 +437,7 @@ static int probe(struct comedi_device *dev, const struct comedi_devconfig *it)
if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue;
/* loop through cards supported by this driver */
for (index = 0; index < N_BOARDS; index++) {
for (index = 0; index < ARRAY_SIZE(boards); index++) {
if (boards[index].device_id != pcidev->device)
continue;
/* was a particular bus/slot requested? */

View File

@ -210,7 +210,7 @@ static struct comedi_driver driver_bonding = {
*/
.board_name = &bondingBoards[0].name,
.offset = sizeof(struct BondingBoard),
.num_names = sizeof(bondingBoards) / sizeof(struct BondingBoard),
.num_names = ARRAY_SIZE(bondingBoards),
};
static int bonding_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -102,7 +102,7 @@ static struct comedi_driver driver_waveform = {
.detach = waveform_detach,
.board_name = &waveform_boards[0].name,
.offset = sizeof(struct waveform_board),
.num_names = sizeof(waveform_boards) / sizeof(struct waveform_board),
.num_names = ARRAY_SIZE(waveform_boards),
};
COMEDI_INITCLEANUP(driver_waveform);

View File

@ -696,8 +696,6 @@ static const struct das16_board das16_boards[] = {
#endif
};
#define n_das16_boards ((sizeof(das16_boards))/(sizeof(struct das16_board)))
static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it);
static int das16_detach(struct comedi_device *dev);
static struct comedi_driver driver_das16 = {
@ -706,7 +704,7 @@ static struct comedi_driver driver_das16 = {
.attach = das16_attach,
.detach = das16_detach,
.board_name = &das16_boards[0].name,
.num_names = n_das16_boards,
.num_names = ARRAY_SIZE(das16_boards),
.offset = sizeof(das16_boards[0]),
};

View File

@ -164,8 +164,6 @@ static const struct das16m1_board das16m1_boards[] = {
},
};
#define das16m1_num_boards ((sizeof(das16m1_boards)) / (sizeof(das16m1_boards[0])))
static int das16m1_attach(struct comedi_device *dev, struct comedi_devconfig *it);
static int das16m1_detach(struct comedi_device *dev);
static struct comedi_driver driver_das16m1 = {
@ -174,7 +172,7 @@ static struct comedi_driver driver_das16m1 = {
.attach = das16m1_attach,
.detach = das16m1_detach,
.board_name = &das16m1_boards[0].name,
.num_names = das16m1_num_boards,
.num_names = ARRAY_SIZE(das16m1_boards),
.offset = sizeof(das16m1_boards[0]),
};

View File

@ -509,7 +509,7 @@ static struct comedi_driver driver_das1800 = {
.module = THIS_MODULE,
.attach = das1800_attach,
.detach = das1800_detach,
.num_names = sizeof(das1800_boards) / sizeof(struct das1800_board),
.num_names = ARRAY_SIZE(das1800_boards),
.board_name = &das1800_boards[0].name,
.offset = sizeof(struct das1800_board),
};

View File

@ -251,7 +251,7 @@ static struct comedi_driver driver_das800 = {
.module = THIS_MODULE,
.attach = das800_attach,
.detach = das800_detach,
.num_names = sizeof(das800_boards) / sizeof(struct das800_board),
.num_names = ARRAY_SIZE(das800_boards),
.board_name = &das800_boards[0].name,
.offset = sizeof(struct das800_board),
};

View File

@ -285,7 +285,7 @@ static struct comedi_driver driver_dmm32at = {
*/
.board_name = &dmm32at_boards[0].name,
.offset = sizeof(struct dmm32at_board),
.num_names = sizeof(dmm32at_boards) / sizeof(struct dmm32at_board),
.num_names = ARRAY_SIZE(dmm32at_boards),
};
/* prototypes for driver functions below */

View File

@ -217,7 +217,6 @@ static const struct dt2801_board boardtypes[] = {
.dabits = 12},
};
#define n_boardtypes ((sizeof(boardtypes))/(sizeof(boardtypes[0])))
#define boardtype (*(const struct dt2801_board *)dev->board_ptr)
struct dt2801_private {
@ -506,7 +505,7 @@ static int dt2801_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (!board_code)
board_code = dt2801_reset(dev);
for (type = 0; type < n_boardtypes; type++) {
for (type = 0; type < ARRAY_SIZE(boardtypes); type++) {
if (boardtypes[type].boardcode == board_code)
goto havetype;
}

View File

@ -222,7 +222,7 @@ static struct comedi_driver driver_dt2811 = {
.attach = dt2811_attach,
.detach = dt2811_detach,
.board_name = &boardtypes[0].name,
.num_names = sizeof(boardtypes) / sizeof(struct dt2811_board),
.num_names = ARRAY_SIZE(boardtypes),
.offset = sizeof(struct dt2811_board),
};

View File

@ -283,11 +283,6 @@ static const struct hpdi_board hpdi_boards[] = {
#endif
};
static inline unsigned int num_boards(void)
{
return sizeof(hpdi_boards) / sizeof(struct hpdi_board);
}
static DEFINE_PCI_DEVICE_TABLE(hpdi_pci_table) = {
{PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX, 0x2400,
0, 0, 0},
@ -568,7 +563,7 @@ static int hpdi_attach(struct comedi_device *dev, struct comedi_devconfig *it)
return -ENOMEM;
pcidev = NULL;
for (i = 0; i < num_boards() && dev->board_ptr == NULL; i++) {
for (i = 0; i < ARRAY_SIZE(hpdi_boards) && dev->board_ptr == NULL; i++) {
do {
pcidev = pci_get_subsys(PCI_VENDOR_ID_PLX,
hpdi_boards[i].device_id, PCI_VENDOR_ID_PLX,

View File

@ -113,7 +113,7 @@ static const struct me4000_board me4000_boards[] = {
{0},
};
#define ME4000_BOARD_VERSIONS (sizeof(me4000_boards) / sizeof(struct me4000_board) - 1)
#define ME4000_BOARD_VERSIONS (ARRAY_SIZE(me4000_boards) - 1)
/*-----------------------------------------------------------------------------
Comedi function prototypes

View File

@ -190,7 +190,7 @@ static struct comedi_driver driver_atao = {
.detach = atao_detach,
.board_name = &atao_boards[0].name,
.offset = sizeof(struct atao_board),
.num_names = sizeof(atao_boards) / sizeof(struct atao_board),
.num_names = ARRAY_SIZE(atao_boards),
};
COMEDI_INITCLEANUP(driver_atao);

View File

@ -104,7 +104,7 @@ static struct comedi_driver driver_dio700 = {
.module = THIS_MODULE,
.attach = dio700_attach,
.detach = dio700_detach,
.num_names = sizeof(dio700_boards) / sizeof(struct dio700_board),
.num_names = ARRAY_SIZE(dio700_boards),
.board_name = &dio700_boards[0].name,
.offset = sizeof(struct dio700_board),
};

View File

@ -104,7 +104,7 @@ static struct comedi_driver driver_dio24 = {
.module = THIS_MODULE,
.attach = dio24_attach,
.detach = dio24_detach,
.num_names = sizeof(dio24_boards) / sizeof(struct dio24_board_struct),
.num_names = ARRAY_SIZE(dio24_boards),
.board_name = &dio24_boards[0].name,
.offset = sizeof(struct dio24_board_struct),
};

View File

@ -434,7 +434,7 @@ static struct comedi_driver driver_labpc = {
.module = THIS_MODULE,
.attach = labpc_attach,
.detach = labpc_common_detach,
.num_names = sizeof(labpc_boards) / sizeof(struct labpc_board_struct),
.num_names = ARRAY_SIZE(labpc_boards),
.board_name = &labpc_boards[0].name,
.offset = sizeof(struct labpc_board_struct),
};

View File

@ -121,7 +121,7 @@ static struct comedi_driver driver_labpc_cs = {
.module = THIS_MODULE,
.attach = &labpc_attach,
.detach = &labpc_common_detach,
.num_names = sizeof(labpc_cs_boards) / sizeof(struct labpc_board_struct),
.num_names = ARRAY_SIZE(labpc_cs_boards),
.board_name = &labpc_cs_boards[0].name,
.offset = sizeof(struct labpc_board_struct),
};

View File

@ -1084,7 +1084,7 @@ static inline int M_Offset_Static_AI_Control(int i)
0x262,
0x263,
};
if (((unsigned)i) >= sizeof(offset) / sizeof(offset[0])) {
if (((unsigned)i) >= ARRAY_SIZE(offset)) {
rt_printk("%s: invalid channel=%i\n", __func__, i);
return offset[0];
}
@ -1098,7 +1098,7 @@ static inline int M_Offset_AO_Reference_Attenuation(int channel)
0x266,
0x267
};
if (((unsigned)channel) >= sizeof(offset) / sizeof(offset[0])) {
if (((unsigned)channel) >= ARRAY_SIZE(offset)) {
rt_printk("%s: invalid channel=%i\n", __func__, channel);
return offset[0];
}

View File

@ -137,7 +137,7 @@ static struct comedi_driver driver = {
*/
.board_name = &pcmda12_boards[0].name,
.offset = sizeof(struct pcmda12_board),
.num_names = sizeof(pcmda12_boards) / sizeof(struct pcmda12_board),
.num_names = ARRAY_SIZE(pcmda12_boards),
};
static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -292,7 +292,7 @@ static struct comedi_driver driver = {
*/
.board_name = &pcmmio_boards[0].name,
.offset = sizeof(struct pcmmio_board),
.num_names = sizeof(pcmmio_boards) / sizeof(struct pcmmio_board),
.num_names = ARRAY_SIZE(pcmmio_boards),
};
static int pcmmio_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -250,7 +250,7 @@ static struct comedi_driver driver = {
*/
.board_name = &pcmuio_boards[0].name,
.offset = sizeof(struct pcmuio_board),
.num_names = sizeof(pcmuio_boards) / sizeof(struct pcmuio_board),
.num_names = ARRAY_SIZE(pcmuio_boards),
};
static int pcmuio_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -757,7 +757,7 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
continue;
}
}
for (i = 0; i < sizeof (rtd520Boards) / sizeof (rtd520Boards[0]); ++i)
for (i = 0; i < ARRAY_SIZE(rtd520Boards); ++i)
{
if (pcidev->device == rtd520Boards[i].device_id)
{

View File

@ -138,7 +138,7 @@ static struct comedi_driver driver_rti800 = {
.module = THIS_MODULE,
.attach = rti800_attach,
.detach = rti800_detach,
.num_names = sizeof(boardtypes) / sizeof(struct rti800_board),
.num_names = ARRAY_SIZE(boardtypes),
.board_name = &boardtypes[0].name,
.offset = sizeof(struct rti800_board),
};
@ -199,8 +199,7 @@ static int rti800_ai_insn_read(struct comedi_device *dev, struct comedi_subdevic
/* without a delay here, the RTI_OVERRUN bit
* gets set, and you will have an error. */
if (insn->n > 0) {
BUG_ON(gain >=
sizeof(gaindelay) / sizeof(gaindelay[0]));
BUG_ON(gain >= ARRAY_SIZE(gaindelay));
comedi_udelay(gaindelay[gain]);
}
}

View File

@ -244,7 +244,7 @@ static struct comedi_driver driver_s526 = {
*/
.board_name = &s526_boards[0].name,
.offset = sizeof(struct s526_board),
.num_names = sizeof(s526_boards) / sizeof(struct s526_board),
.num_names = ARRAY_SIZE(s526_boards),
};
static int s526_gpct_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -2358,7 +2358,7 @@ static void LoadTrimDACs(struct comedi_device *dev)
register uint8_t i;
/* Copy TrimDac setpoint values from EEPROM to TrimDacs. */
for (i = 0; i < (sizeof(trimchan) / sizeof(trimchan[0])); i++)
for (i = 0; i < ARRAY_SIZE(trimchan); i++)
WriteTrimDAC(dev, i, I2Cread(dev, trimadrs[i]));
}

View File

@ -98,7 +98,7 @@ struct comedi_driver driver_serial2002 = {
.detach = serial2002_detach,
.board_name = &serial2002_boards[0].name,
.offset = sizeof(struct serial2002_board),
.num_names = sizeof(serial2002_boards) / sizeof(struct serial2002_board),
.num_names = ARRAY_SIZE(serial2002_boards),
};
static int serial2002_di_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -181,7 +181,7 @@ static struct comedi_driver driver_skel = {
*/
.board_name = &skel_boards[0].name,
.offset = sizeof(struct skel_board),
.num_names = sizeof(skel_boards) / sizeof(struct skel_board),
.num_names = ARRAY_SIZE(skel_boards),
};
static int skel_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,

View File

@ -99,7 +99,7 @@ static struct comedi_driver driver_dnp = {
.board_name = &dnp_boards[0].name,
/* only necessary for non-PnP devs */
.offset = sizeof(struct dnp_board),/* like ISA-PnP, PCI or PCMCIA. */
.num_names = sizeof(dnp_boards) / sizeof(struct dnp_board),
.num_names = ARRAY_SIZE(dnp_boards),
};
COMEDI_INITCLEANUP(driver_dnp);