sys/dev: use our nitems() macro when it is avaliable through param.h.

No functional change, only trivial cases are done in this sweep,
Drivers that can get further enhancements will be done independently.

Discussed in:	freebsd-current
This commit is contained in:
Pedro F. Giffuni 2016-04-19 23:37:24 +00:00
parent 4ec642f1d6
commit 73a1170a8c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298307
41 changed files with 65 additions and 78 deletions

View File

@ -162,7 +162,7 @@ keycode2scancode(int keycode, int shift, int up)
int scancode;
scancode = keycode;
if ((keycode >= 89) && (keycode < 89 + sizeof(scan) / sizeof(scan[0])))
if ((keycode >= 89) && (keycode < 89 + nitems(scan)))
scancode = scan[keycode - 89] | SCAN_PREFIX_E0;
/* pause/break */
if ((keycode == 104) && !(shift & CTLS))

View File

@ -323,8 +323,7 @@ age_probe(device_t dev)
vendor = pci_get_vendor(dev);
devid = pci_get_device(dev);
sp = age_devs;
for (i = 0; i < sizeof(age_devs) / sizeof(age_devs[0]);
i++, sp++) {
for (i = 0; i < nitems(age_devs); i++, sp++) {
if (vendor == sp->age_vendorid &&
devid == sp->age_deviceid) {
device_set_desc(dev, sp->age_name);

View File

@ -310,8 +310,7 @@ aha_isa_identify(driver_t *driver, device_t parent)
device_t child;
/* Attempt to find an adapter */
for (i = 0; i < sizeof(aha_board_ports) / sizeof(aha_board_ports[0]);
i++) {
for (i = 0; i < nitems(aha_board_ports); i++) {
bzero(&aha, sizeof(aha));
ioport = aha_board_ports[i];
/*

View File

@ -343,7 +343,7 @@ ale_probe(device_t dev)
vendor = pci_get_vendor(dev);
devid = pci_get_device(dev);
sp = ale_devs;
for (i = 0; i < sizeof(ale_devs) / sizeof(ale_devs[0]); i++) {
for (i = 0; i < nitems(ale_devs); i++) {
if (vendor == sp->ale_vendorid &&
devid == sp->ale_deviceid) {
device_set_desc(dev, sp->ale_name);

View File

@ -1727,8 +1727,7 @@ atse_sysctl_stats_attach(device_t dev)
soid = device_get_sysctl_tree(dev);
/* MAC statistics. */
for (i = 0; i < sizeof(atse_mac_stats_regs) /
sizeof(*atse_mac_stats_regs); i++) {
for (i = 0; i < nitems(atse_mac_stats_regs); i++) {
if (atse_mac_stats_regs[i].name == NULL ||
atse_mac_stats_regs[i].descr == NULL)
continue;

View File

@ -362,8 +362,7 @@ atkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
keymap = &default_keymap;
accmap = &default_accentmap;
fkeymap = default_fkeytab;
fkeymap_size =
sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
fkeymap_size = nitems(default_fkeytab);
needfree = 0;
} else if (*kbdp == NULL) {
*kbdp = kbd = malloc(sizeof(*kbd), M_DEVBUF, M_NOWAIT | M_ZERO);
@ -1506,12 +1505,12 @@ typematic(int delay, int rate)
int value;
int i;
for (i = sizeof(delays)/sizeof(delays[0]) - 1; i > 0; --i) {
for (i = nitems(delays) - 1; i > 0; --i) {
if (delay >= delays[i])
break;
}
value = i << 5;
for (i = sizeof(rates)/sizeof(rates[0]) - 1; i > 0; --i) {
for (i = nitems(rates) - 1; i > 0; --i) {
if (rate >= rates[i])
break;
}

View File

@ -154,7 +154,7 @@ atkbdc_softc_t
{
atkbdc_softc_t *sc;
if (unit >= sizeof(atkbdc_softc)/sizeof(atkbdc_softc[0]))
if (unit >= nitems(atkbdc_softc))
return NULL;
sc = atkbdc_softc[unit];
if (sc == NULL) {

View File

@ -524,8 +524,7 @@ static struct {
{ MOUSE_MODEL_GENERIC,
0xc0, MOUSE_PS2_PACKETSIZE, NULL },
};
#define GENERIC_MOUSE_ENTRY \
((sizeof(vendortype) / sizeof(*vendortype)) - 1)
#define GENERIC_MOUSE_ENTRY (nitems(vendortype) - 1)
/* device driver declarateion */
static device_method_t psm_methods[] = {
@ -3874,7 +3873,7 @@ enable_kmouse(struct psm_softc *sc, enum probearg arg)
* The special sequence to enable the third and fourth buttons.
* Otherwise they behave like the first and second buttons.
*/
for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
for (i = 0; i < nitems(rate); ++i)
if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
return (FALSE);
@ -3971,7 +3970,7 @@ enable_msexplorer(struct psm_softc *sc, enum probearg arg)
enable_msintelli(sc, arg);
/* the special sequence to enable the extra buttons and the roller. */
for (i = 0; i < sizeof(rate1)/sizeof(rate1[0]); ++i)
for (i = 0; i < nitems(rate1); ++i)
if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i])
return (FALSE);
/* the device will give the genuine ID only after the above sequence */
@ -3994,7 +3993,7 @@ enable_msexplorer(struct psm_softc *sc, enum probearg arg)
* sequence; it will make the KVM think the mouse is IntelliMouse
* when it is in fact IntelliMouse Explorer.
*/
for (i = 0; i < sizeof(rate0)/sizeof(rate0[0]); ++i)
for (i = 0; i < nitems(rate0); ++i)
if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i])
break;
get_aux_id(kbdc);
@ -4016,7 +4015,7 @@ enable_msintelli(struct psm_softc *sc, enum probearg arg)
int i;
/* the special sequence to enable the third button and the roller. */
for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
for (i = 0; i < nitems(rate); ++i)
if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
return (FALSE);
/* the device will give the genuine ID only after the above sequence */
@ -4044,7 +4043,7 @@ enable_4dmouse(struct psm_softc *sc, enum probearg arg)
int id;
int i;
for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
for (i = 0; i < nitems(rate); ++i)
if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
return (FALSE);
id = get_aux_id(kbdc);

View File

@ -324,7 +324,7 @@ static struct meteor_pixfmt_internal {
{ { 0, METEOR_PIXTYPE_YUV_12, 2, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }, 0x88 },
};
#define PIXFMT_TABLE_SIZE ( sizeof(pixfmt_table) / sizeof(pixfmt_table[0]) )
#define PIXFMT_TABLE_SIZE nitems(pixfmt_table)
/*
* Table of Meteor-supported Pixel Formats (for SETGEO compatibility)
@ -354,8 +354,7 @@ static struct {
},
};
#define METEOR_PIXFMT_TABLE_SIZE ( sizeof(meteor_pixfmt_table) / \
sizeof(meteor_pixfmt_table[0]) )
#define METEOR_PIXFMT_TABLE_SIZE nitems(meteor_pixfmt_table)
#define BSWAP (BT848_COLOR_CTL_BSWAP_ODD | BT848_COLOR_CTL_BSWAP_EVEN)

View File

@ -1018,8 +1018,7 @@ bwi_rf_calibval(struct bwi_mac *mac)
val = RF_READ(mac, BWI_RFR_BBP_ATTEN);
idx = __SHIFTOUT(val, BWI_RFR_BBP_ATTEN_CALIB_IDX);
KASSERT(idx < (int)(sizeof(rf_calibvals) / sizeof(rf_calibvals[0])),
("idx %d", idx));
KASSERT(idx < (int)nitems(rf_calibvals), ("idx %d", idx));
calib = rf_calibvals[idx] << 1;
if (val & BWI_RFR_BBP_ATTEN_CALIB_BIT)

View File

@ -906,7 +906,7 @@ bwn_probe(device_t dev)
{
int i;
for (i = 0; i < sizeof(bwn_devs) / sizeof(bwn_devs[0]); i++) {
for (i = 0; i < nitems(bwn_devs); i++) {
if (siba_get_vendor(dev) == bwn_devs[i].sd_vendor &&
siba_get_device(dev) == bwn_devs[i].sd_device &&
siba_get_revid(dev) == bwn_devs[i].sd_rev)

View File

@ -205,7 +205,7 @@ decode_tuple_funcid(device_t cbdev, device_t child, int id,
struct tuple_callbacks *info, void *argp)
{
struct cardbus_devinfo *dinfo = device_get_ivars(child);
int numnames = sizeof(funcnames) / sizeof(funcnames[0]);
int numnames = nitems(funcnames);
int i;
if (cardbus_cis_debug) {

View File

@ -1441,8 +1441,8 @@ digi_errortxt(int id)
"tty-level buffer overflow",
};
KASSERT(id >= 0 && id < sizeof(error_desc) / sizeof(error_desc[0]),
("Unexpected digi error id %d\n", id));
KASSERT(id >= 0 && id < nitems(error_desc),
("Unexpected digi error id %d\n", id));
return (error_desc[id]);
}

View File

@ -58,7 +58,7 @@ __FBSDID("$FreeBSD$");
static u_long digi_validio[] = {
0x100, 0x110, 0x120, 0x200, 0x220, 0x300, 0x320
};
#define DIGI_NVALIDIO (sizeof(digi_validio) / sizeof(digi_validio[0]))
#define DIGI_NVALIDIO nitems(digi_validio)
#define IO_SIZE 0x04
static u_long digi_validmem[] = {
@ -68,7 +68,7 @@ static u_long digi_validmem[] = {
0xf6000000, 0xf7000000, 0xf8000000, 0xf9000000, 0xfa000000, 0xfb000000,
0xfc000000, 0xfd000000, 0xfe000000, 0xff000000
};
#define DIGI_NVALIDMEM (sizeof(digi_validmem) / sizeof(digi_validmem[0]))
#define DIGI_NVALIDMEM (nitems(digi_validmem))
static u_char *
digi_isa_setwin(struct digi_softc *sc, unsigned int addr)

View File

@ -1049,7 +1049,7 @@ dwc_reset(device_t dev)
}
if (GPIO_MAP_GPIOS(gpio, node, gpio_node,
sizeof(gpio_prop) / sizeof(gpio_prop[0]) - 1,
nitems(gpio_prop) - 1,
gpio_prop + 1, &pin, &flags) != 0) {
device_printf(dev, "Can't map gpio for phy reset\n");
return (ENXIO);

View File

@ -214,7 +214,7 @@ ed_probe_HP_pclanp(device_t dev, int port_rid, int flags)
* Check for impossible IRQ.
*/
if (irq >= (sizeof(ed_hpp_intr_val) / sizeof(ed_hpp_intr_val[0])))
if (irq >= (nitems(ed_hpp_intr_val)))
return (ENXIO);
/*

View File

@ -202,5 +202,5 @@ DRIVER_MODULE(ed, isa, ed_isa_driver, ed_devclass, 0, 0);
MODULE_DEPEND(ed, isa, 1, 1, 1);
MODULE_DEPEND(ed, ether, 1, 1, 1);
MODULE_PNP_INFO("E:pnpid;", isa, ed, ed_ids, sizeof(ed_ids[0]),
sizeof(ed_ids) / sizeof(ed_ids[0]) - 1);
nitems(ed_ids) - 1);

View File

@ -144,5 +144,5 @@ DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
MODULE_DEPEND(ed, pci, 1, 1, 1);
MODULE_DEPEND(ed, ether, 1, 1, 1);
MODULE_PNP_INFO("W32:vendor/device;D:human", pci, ed, pci_ids, sizeof(pci_ids[0]),
sizeof(pci_ids) / sizeof(pci_ids[0]) - 1);
nitems(pci_ids) - 1);

View File

@ -189,7 +189,7 @@ mx25l_get_device_ident(struct mx25l_softc *sc)
dev_id = (rxBuf[2] << 8) | (rxBuf[3]);
for (i = 0;
i < sizeof(flash_devices)/sizeof(struct mx25l_flash_ident); i++) {
i < nitems(flash_devices); i++) {
if ((flash_devices[i].manufacturer_id == manufacturer_id) &&
(flash_devices[i].device_id == dev_id))
return &flash_devices[i];

View File

@ -608,7 +608,7 @@ hatm_read_prom_byte(struct hatm_softc *sc, u_int addr)
BARRIER_W(sc);
/* send READ */
for (i = 0; i < sizeof(readtab) / sizeof(readtab[0]); i++) {
for (i = 0; i < nitems(readtab); i++) {
WRITE4(sc, HE_REGO_HOST_CNTL, val | readtab[i]);
BARRIER_W(sc);
DELAY(EEPROM_DELAY);

View File

@ -1029,7 +1029,7 @@ hifn_enable_crypto(struct hifn_softc *sc)
u_int32_t dmacfg, ramcfg, encl, addr, i;
char *offtbl = NULL;
for (i = 0; i < sizeof(pci2id)/sizeof(pci2id[0]); i++) {
for (i = 0; i < nitems(pci2id); i++) {
if (pci2id[i].pci_vendor == pci_get_vendor(sc->sc_dev) &&
pci2id[i].pci_prod == pci_get_device(sc->sc_dev)) {
offtbl = pci2id[i].card_id;

View File

@ -2400,7 +2400,7 @@ ndis_setstate_80211(struct ndis_softc *sc)
/* Set TX power */
if ((ic->ic_caps & IEEE80211_C_TXPMGT) &&
ic->ic_txpowlimit < (sizeof(dBm2mW) / sizeof(dBm2mW[0]))) {
ic->ic_txpowlimit < nitems(dBm2mW)) {
arg = dBm2mW[ic->ic_txpowlimit];
len = sizeof(arg);
ndis_set_info(sc, OID_802_11_TX_POWER_LEVEL, &arg, &len);
@ -2810,7 +2810,7 @@ ndis_getstate_80211(struct ndis_softc *sc)
if (ic->ic_caps & IEEE80211_C_TXPMGT) {
len = sizeof(arg);
ndis_get_info(sc, OID_802_11_TX_POWER_LEVEL, &arg, &len);
for (i = 0; i < (sizeof(dBm2mW) / sizeof(dBm2mW[0])); i++)
for (i = 0; i < nitems(dBm2mW); i++)
if (dBm2mW[i] >= arg)
break;
ic->ic_txpowlimit = i;

View File

@ -337,8 +337,7 @@ jme_probe(device_t dev)
vendor = pci_get_vendor(dev);
devid = pci_get_device(dev);
sp = jme_devs;
for (i = 0; i < sizeof(jme_devs) / sizeof(jme_devs[0]);
i++, sp++) {
for (i = 0; i < nitems(jme_devs); i++, sp++) {
if (vendor == sp->jme_vendorid &&
devid == sp->jme_deviceid) {
device_set_desc(dev, sp->jme_name);

View File

@ -1144,7 +1144,7 @@ static char
};
int i;
for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
for (i = 0; i < nitems(name_table); ++i) {
if (type == name_table[i].type)
return (name_table[i].name);
}

View File

@ -1364,7 +1364,7 @@ mlx_periodic_eventlog_respond(struct mlx_command *mc)
/* Mylex vendor-specific message indicating a drive was killed? */
if ((el->el_sensekey == 9) &&
(el->el_asc == 0x80)) {
if (el->el_asq < (sizeof(mlx_sense_messages) / sizeof(mlx_sense_messages[0]))) {
if (el->el_asq < nitems(mlx_sense_messages)) {
reason = mlx_sense_messages[el->el_asq];
} else {
reason = "for unknown reason";

View File

@ -2994,16 +2994,14 @@ mxge_media_probe(mxge_softc_t *sc)
/* -R is XFP */
mxge_media_types = mxge_xfp_media_types;
mxge_media_type_entries =
sizeof (mxge_xfp_media_types) /
sizeof (mxge_xfp_media_types[0]);
nitems(mxge_xfp_media_types);
byte = MXGE_XFP_COMPLIANCE_BYTE;
cage_type = "XFP";
} else if (sc->connector == MXGE_SFP) {
/* -S or -2S is SFP+ */
mxge_media_types = mxge_sfp_media_types;
mxge_media_type_entries =
sizeof (mxge_sfp_media_types) /
sizeof (mxge_sfp_media_types[0]);
nitems(mxge_sfp_media_types);
cage_type = "SFP+";
byte = 3;
} else {

View File

@ -59,7 +59,7 @@ struct nand_params *nand_get_params(struct nand_id *id)
{
int i;
for (i = 0; i < sizeof(nand_ids) / sizeof(nand_ids[0]); i++)
for (i = 0; i < nitems(nand_ids); i++)
if (nand_ids[i].id.man_id == id->man_id &&
nand_ids[i].id.dev_id == id->dev_id)
return (&nand_ids[i]);

View File

@ -3230,7 +3230,7 @@ static int ncr_chip_lookup(u_long device_id, u_char revision_id)
int i, found;
found = -1;
for (i = 0; i < sizeof(ncr_chip_table)/sizeof(ncr_chip_table[0]); i++) {
for (i = 0; i < nitems(ncr_chip_table); i++) {
if (device_id == ncr_chip_table[i].device_id &&
ncr_chip_table[i].minrevid <= revision_id) {
if (found < 0 ||

View File

@ -455,7 +455,7 @@ nct_probe(device_t dev)
sc = device_get_softc(dev);
for (i = 0; i < sizeof(probe_addrs) / sizeof(*probe_addrs); i++) {
for (i = 0; i < nitems(probe_addrs); i++) {
sc->rid = 0;
sc->portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->rid,
probe_addrs[i], probe_addrs[i] + 1, 2, RF_ACTIVE);
@ -476,7 +476,7 @@ nct_probe(device_t dev)
bus_release_resource(dev, SYS_RES_IOPORT, sc->rid, sc->portres);
bus_delete_resource(dev, SYS_RES_IOPORT, sc->rid);
for (j = 0; j < sizeof(nct_devs) / sizeof(*nct_devs); j++) {
for (j = 0; j < nitems(nct_devs); j++) {
if (chipid == nct_devs[j].chip_id) {
rc = bus_set_resource(dev, SYS_RES_IOPORT, 0, probe_addrs[i], 2);
if (rc != 0) {

View File

@ -843,7 +843,7 @@ nfe_can_use_msix(struct nfe_softc *sc)
product = kern_getenv("smbios.planar.product");
use_msix = 1;
if (maker != NULL && product != NULL) {
count = sizeof(msix_blacklists) / sizeof(msix_blacklists[0]);
count = nitems(msix_blacklists);
mblp = msix_blacklists;
for (n = 0; n < count; n++) {
if (strcmp(maker, mblp->maker) == 0 &&

View File

@ -675,7 +675,7 @@ patm_read_eeprom(struct patm_softc *sc)
gp = patm_nor_read(sc, IDT_NOR_GP);
gp &= ~(IDT_GP_EESCLK | IDT_GP_EECS | IDT_GP_EEDO);
for (i = 0; i < sizeof(tab) / sizeof(tab[0]); i++) {
for (i = 0; i < nitems(tab); i++) {
patm_nor_write(sc, IDT_NOR_GP, gp | tab[i]);
DELAY(40);
}

View File

@ -186,7 +186,7 @@ rc_probe(device_t dev)
if (port == -1)
return (ENXIO);
found = 0;
for (i = 0; i < sizeof(rc_ports) / sizeof(int); i++)
for (i = 0; i < nitems(rc_ports); i++)
if (rc_ports[i] == port) {
found = 1;
break;

View File

@ -953,7 +953,7 @@ re_probe(device_t dev)
}
t = re_devs;
for (i = 0; i < sizeof(re_devs) / sizeof(re_devs[0]); i++, t++) {
for (i = 0; i < nitems(re_devs); i++, t++) {
if (vendor == t->rl_vid && devid == t->rl_did) {
device_set_desc(dev, t->rl_name);
return (BUS_PROBE_DEFAULT);

View File

@ -598,7 +598,7 @@ rl_probe(device_t dev)
}
}
t = rl_devs;
for (i = 0; i < sizeof(rl_devs) / sizeof(rl_devs[0]); i++, t++) {
for (i = 0; i < nitems(rl_devs); i++, t++) {
if (vendor == t->rl_vid && devid == t->rl_did) {
device_set_desc(dev, t->rl_name);
return (BUS_PROBE_DEFAULT);

View File

@ -710,7 +710,7 @@ sf_probe(device_t dev)
sdid = pci_get_subdevice(dev);
t = sf_devs;
for (i = 0; i < sizeof(sf_devs) / sizeof(sf_devs[0]); i++, t++) {
for (i = 0; i < nitems(sf_devs); i++, t++) {
if (vid == t->sf_vid && did == t->sf_did) {
if (sdid == t->sf_sdid) {
device_set_desc(dev, t->sf_sname);

View File

@ -1638,7 +1638,7 @@ if (com->iptr - com->ibuf == 8)
outb(com->data_port, *ioptr++);
++com->bytes_out;
if (com->unit == siotsunit
&& siotso < sizeof siots / sizeof siots[0])
&& siotso < nitems(siots))
nanouptime(&siots[siotso++]);
}
com->obufq.l_head = ioptr;

View File

@ -491,7 +491,7 @@ alloc_resource(sc_p scp)
base = isa_get_port(scp->dev);
else
base = 0;
for (i = 0 ; i < sizeof(scp->io) / sizeof(*scp->io) ; i++) {
for (i = 0 ; i < nitems(scp->io); i++) {
if (scp->io[i] == NULL) {
scp->io_rid[i] = i;
if (base == 0)
@ -521,7 +521,7 @@ alloc_resource(sc_p scp)
return (1);
scp->irq_alloced = 0;
}
for (i = 0 ; i < sizeof(scp->drq) / sizeof(*scp->drq) ; i++) {
for (i = 0 ; i < nitems(scp->drq); i++) {
if (scp->drq[i] == NULL) {
scp->drq_rid[i] = i;
if (base == 0 || i == 0)
@ -597,7 +597,7 @@ release_resource(sc_p scp)
switch(lid) {
case LOGICALID_PCM:
case LOGICALID_NOPNP: /* XXX Non-PnP */
for (i = 0 ; i < sizeof(scp->io) / sizeof(*scp->io) ; i++) {
for (i = 0 ; i < nitems(scp->io); i++) {
if (scp->io[i] != NULL) {
bus_release_resource(scp->dev, SYS_RES_IOPORT, scp->io_rid[i], scp->io[i]);
scp->io[i] = NULL;
@ -607,7 +607,7 @@ release_resource(sc_p scp)
bus_release_resource(scp->dev, SYS_RES_IRQ, scp->irq_rid, scp->irq);
scp->irq = NULL;
}
for (i = 0 ; i < sizeof(scp->drq) / sizeof(*scp->drq) ; i++) {
for (i = 0 ; i < nitems(scp->drq); i++) {
if (scp->drq[i] != NULL) {
bus_release_resource(scp->dev, SYS_RES_DRQ, scp->drq_rid[i], scp->drq[i]);
scp->drq[i] = NULL;

View File

@ -327,15 +327,13 @@ playstring(char *cp, size_t slen)
slen--;
} else {
GETNUM(cp, octave);
if (octave >= sizeof(pitchtab) / sizeof(pitchtab[0]) /
OCTAVE_NOTES)
if (octave >= nitems(pitchtab) / OCTAVE_NOTES)
octave = DFLT_OCTAVE;
octprefix = TRUE;
}
break;
case '>':
if (octave < sizeof(pitchtab) / sizeof(pitchtab[0]) /
OCTAVE_NOTES - 1)
if (octave < nitems(pitchtab) / OCTAVE_NOTES - 1)
octave++;
octprefix = TRUE;
break;

View File

@ -416,8 +416,7 @@ stge_probe(device_t dev)
vendor = pci_get_vendor(dev);
devid = pci_get_device(dev);
sp = stge_products;
for (i = 0; i < sizeof(stge_products)/sizeof(stge_products[0]);
i++, sp++) {
for (i = 0; i < nitems(stge_products); i++, sp++) {
if (vendor == sp->stge_vendorid &&
devid == sp->stge_deviceid) {
device_set_desc(dev, sp->stge_name);

View File

@ -380,11 +380,11 @@ vkbd_dev_write(struct cdev *dev, struct uio *uio, int flag)
while (uio->uio_resid >= sizeof(q->q[0])) {
if (q->head == q->tail) {
if (q->cc == 0)
avail = sizeof(q->q)/sizeof(q->q[0]) - q->head;
avail = nitems(q->q) - q->head;
else
avail = 0; /* queue must be full */
} else if (q->head < q->tail)
avail = sizeof(q->q)/sizeof(q->q[0]) - q->tail;
avail = nitems(q->q) - q->tail;
else
avail = q->head - q->tail;
@ -410,7 +410,7 @@ vkbd_dev_write(struct cdev *dev, struct uio *uio, int flag)
q->cc += avail;
q->tail += avail;
if (q->tail == sizeof(q->q)/sizeof(q->q[0]))
if (q->tail == nitems(q->q))
q->tail = 0;
/* queue interrupt task if needed */
@ -459,7 +459,7 @@ vkbd_dev_poll(struct cdev *dev, int events, struct thread *td)
}
if (events & (POLLOUT | POLLWRNORM)) {
if (q->cc < sizeof(q->q)/sizeof(q->q[0]))
if (q->cc < nitems(q->q))
revents |= events & (POLLOUT | POLLWRNORM);
else
selrecord(td, &state->ks_wsel);
@ -524,7 +524,7 @@ vkbd_data_read(vkbd_state_t *state, int wait)
/* get first code from the queue */
q->cc --;
c = q->q[q->head ++];
if (q->head == sizeof(q->q)/sizeof(q->q[0]))
if (q->head == nitems(q->q))
q->head = 0;
/* wakeup ks_inq writers/poll()ers */
@ -1326,12 +1326,12 @@ typematic(int delay, int rate)
int value;
int i;
for (i = sizeof(delays)/sizeof(delays[0]) - 1; i > 0; i --) {
for (i = nitems(delays) - 1; i > 0; i --) {
if (delay >= delays[i])
break;
}
value = i << 5;
for (i = sizeof(rates)/sizeof(rates[0]) - 1; i > 0; i --) {
for (i = nitems(rates) - 1; i > 0; i --) {
if (rate >= rates[i])
break;
}

View File

@ -619,7 +619,7 @@ wb_probe_enable(device_t dev, int probe)
error = ENXIO;
found = 0;
for (i = 0; i < sizeof(probe_addrs) / sizeof(*probe_addrs); i++) {
for (i = 0; i < nitems(probe_addrs); i++) {
if (sc != NULL) {
/* Allocate bus resources for IO index/data register access. */
@ -657,7 +657,7 @@ wb_probe_enable(device_t dev, int probe)
goto cleanup;
}
for (j = 0; j < sizeof(wb_devs) / sizeof(*wb_devs); j++) {
for (j = 0; j < nitems(wb_devs); j++) {
if (wb_devs[j].device_id == dev_id) {
found = 1;
break;