summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-04-19 23:37:24 +0000
committerpfg <pfg@FreeBSD.org>2016-04-19 23:37:24 +0000
commite2a6cba6516fcfe2c4f3ff73d0f9aa0ba261f548 (patch)
tree346d2ff1b645f831d2f412a7a4be3f6eb1c711b4
parentea58c6f194dc25f7e2e87f7a36de9b2da5b8b90c (diff)
downloadFreeBSD-src-e2a6cba6516fcfe2c4f3ff73d0f9aa0ba261f548.zip
FreeBSD-src-e2a6cba6516fcfe2c4f3ff73d0f9aa0ba261f548.tar.gz
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
-rw-r--r--sys/dev/adb/adb_kbd.c2
-rw-r--r--sys/dev/age/if_age.c3
-rw-r--r--sys/dev/aha/aha_isa.c3
-rw-r--r--sys/dev/ale/if_ale.c2
-rw-r--r--sys/dev/altera/atse/if_atse.c3
-rw-r--r--sys/dev/atkbdc/atkbd.c7
-rw-r--r--sys/dev/atkbdc/atkbdc.c2
-rw-r--r--sys/dev/atkbdc/psm.c13
-rw-r--r--sys/dev/bktr/bktr_core.c5
-rw-r--r--sys/dev/bwi/bwirf.c3
-rw-r--r--sys/dev/bwn/if_bwn.c2
-rw-r--r--sys/dev/cardbus/cardbus_cis.c2
-rw-r--r--sys/dev/digi/digi.c4
-rw-r--r--sys/dev/digi/digi_isa.c4
-rw-r--r--sys/dev/dwc/if_dwc.c2
-rw-r--r--sys/dev/ed/if_ed_hpp.c2
-rw-r--r--sys/dev/ed/if_ed_isa.c2
-rw-r--r--sys/dev/ed/if_ed_pci.c2
-rw-r--r--sys/dev/flash/mx25l.c2
-rw-r--r--sys/dev/hatm/if_hatm.c2
-rw-r--r--sys/dev/hifn/hifn7751.c2
-rw-r--r--sys/dev/if_ndis/if_ndis.c4
-rw-r--r--sys/dev/jme/if_jme.c3
-rw-r--r--sys/dev/kbd/kbd.c2
-rw-r--r--sys/dev/mlx/mlx.c2
-rw-r--r--sys/dev/mxge/if_mxge.c6
-rw-r--r--sys/dev/nand/nand_id.c2
-rw-r--r--sys/dev/ncr/ncr.c2
-rw-r--r--sys/dev/nctgpio/nctgpio.c4
-rw-r--r--sys/dev/nfe/if_nfe.c2
-rw-r--r--sys/dev/patm/if_patm_attach.c2
-rw-r--r--sys/dev/rc/rc.c2
-rw-r--r--sys/dev/re/if_re.c2
-rw-r--r--sys/dev/rl/if_rl.c2
-rw-r--r--sys/dev/sf/if_sf.c2
-rw-r--r--sys/dev/sio/sio.c2
-rw-r--r--sys/dev/sound/isa/gusc.c8
-rw-r--r--sys/dev/speaker/spkr.c6
-rw-r--r--sys/dev/stge/if_stge.c3
-rw-r--r--sys/dev/vkbd/vkbd.c14
-rw-r--r--sys/dev/wbwd/wbwd.c4
41 files changed, 65 insertions, 78 deletions
diff --git a/sys/dev/adb/adb_kbd.c b/sys/dev/adb/adb_kbd.c
index 2fe7609..cd2a9a7 100644
--- a/sys/dev/adb/adb_kbd.c
+++ b/sys/dev/adb/adb_kbd.c
@@ -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))
diff --git a/sys/dev/age/if_age.c b/sys/dev/age/if_age.c
index 9e2fec8..8ed176e 100644
--- a/sys/dev/age/if_age.c
+++ b/sys/dev/age/if_age.c
@@ -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);
diff --git a/sys/dev/aha/aha_isa.c b/sys/dev/aha/aha_isa.c
index c4e7ba9..db6fa0c 100644
--- a/sys/dev/aha/aha_isa.c
+++ b/sys/dev/aha/aha_isa.c
@@ -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];
/*
diff --git a/sys/dev/ale/if_ale.c b/sys/dev/ale/if_ale.c
index e4db2fa..e7d0306 100644
--- a/sys/dev/ale/if_ale.c
+++ b/sys/dev/ale/if_ale.c
@@ -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);
diff --git a/sys/dev/altera/atse/if_atse.c b/sys/dev/altera/atse/if_atse.c
index 1c55fbc..5e37ad2 100644
--- a/sys/dev/altera/atse/if_atse.c
+++ b/sys/dev/altera/atse/if_atse.c
@@ -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;
diff --git a/sys/dev/atkbdc/atkbd.c b/sys/dev/atkbdc/atkbd.c
index a90f5d2..8fba578 100644
--- a/sys/dev/atkbdc/atkbd.c
+++ b/sys/dev/atkbdc/atkbd.c
@@ -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;
}
diff --git a/sys/dev/atkbdc/atkbdc.c b/sys/dev/atkbdc/atkbdc.c
index 69ffa63..695e6bf 100644
--- a/sys/dev/atkbdc/atkbdc.c
+++ b/sys/dev/atkbdc/atkbdc.c
@@ -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) {
diff --git a/sys/dev/atkbdc/psm.c b/sys/dev/atkbdc/psm.c
index 0103baf..b5c4856 100644
--- a/sys/dev/atkbdc/psm.c
+++ b/sys/dev/atkbdc/psm.c
@@ -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);
diff --git a/sys/dev/bktr/bktr_core.c b/sys/dev/bktr/bktr_core.c
index 764eda5..67f3ab1 100644
--- a/sys/dev/bktr/bktr_core.c
+++ b/sys/dev/bktr/bktr_core.c
@@ -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)
diff --git a/sys/dev/bwi/bwirf.c b/sys/dev/bwi/bwirf.c
index 341e929..e65a80d 100644
--- a/sys/dev/bwi/bwirf.c
+++ b/sys/dev/bwi/bwirf.c
@@ -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)
diff --git a/sys/dev/bwn/if_bwn.c b/sys/dev/bwn/if_bwn.c
index decef5f..a7b0480 100644
--- a/sys/dev/bwn/if_bwn.c
+++ b/sys/dev/bwn/if_bwn.c
@@ -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)
diff --git a/sys/dev/cardbus/cardbus_cis.c b/sys/dev/cardbus/cardbus_cis.c
index f9f7816..00c34a6 100644
--- a/sys/dev/cardbus/cardbus_cis.c
+++ b/sys/dev/cardbus/cardbus_cis.c
@@ -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) {
diff --git a/sys/dev/digi/digi.c b/sys/dev/digi/digi.c
index 7adc72a..b8ede24 100644
--- a/sys/dev/digi/digi.c
+++ b/sys/dev/digi/digi.c
@@ -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]);
}
diff --git a/sys/dev/digi/digi_isa.c b/sys/dev/digi/digi_isa.c
index 647ea1d..d549110 100644
--- a/sys/dev/digi/digi_isa.c
+++ b/sys/dev/digi/digi_isa.c
@@ -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)
diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c
index 1984c48..988516e 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -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);
diff --git a/sys/dev/ed/if_ed_hpp.c b/sys/dev/ed/if_ed_hpp.c
index ec5c8db..85df356 100644
--- a/sys/dev/ed/if_ed_hpp.c
+++ b/sys/dev/ed/if_ed_hpp.c
@@ -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);
/*
diff --git a/sys/dev/ed/if_ed_isa.c b/sys/dev/ed/if_ed_isa.c
index 7b1a6b7..7b974dc 100644
--- a/sys/dev/ed/if_ed_isa.c
+++ b/sys/dev/ed/if_ed_isa.c
@@ -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);
diff --git a/sys/dev/ed/if_ed_pci.c b/sys/dev/ed/if_ed_pci.c
index 31b9762..04130df 100644
--- a/sys/dev/ed/if_ed_pci.c
+++ b/sys/dev/ed/if_ed_pci.c
@@ -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);
diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c
index 645fb36..9b5b9aa 100644
--- a/sys/dev/flash/mx25l.c
+++ b/sys/dev/flash/mx25l.c
@@ -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];
diff --git a/sys/dev/hatm/if_hatm.c b/sys/dev/hatm/if_hatm.c
index 0677a14..d1dd6b1 100644
--- a/sys/dev/hatm/if_hatm.c
+++ b/sys/dev/hatm/if_hatm.c
@@ -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);
diff --git a/sys/dev/hifn/hifn7751.c b/sys/dev/hifn/hifn7751.c
index ba510be..65dbfab 100644
--- a/sys/dev/hifn/hifn7751.c
+++ b/sys/dev/hifn/hifn7751.c
@@ -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;
diff --git a/sys/dev/if_ndis/if_ndis.c b/sys/dev/if_ndis/if_ndis.c
index 47594fc..5084202 100644
--- a/sys/dev/if_ndis/if_ndis.c
+++ b/sys/dev/if_ndis/if_ndis.c
@@ -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;
diff --git a/sys/dev/jme/if_jme.c b/sys/dev/jme/if_jme.c
index d3a1057..f2567cc 100644
--- a/sys/dev/jme/if_jme.c
+++ b/sys/dev/jme/if_jme.c
@@ -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);
diff --git a/sys/dev/kbd/kbd.c b/sys/dev/kbd/kbd.c
index 8036762..45f483a 100644
--- a/sys/dev/kbd/kbd.c
+++ b/sys/dev/kbd/kbd.c
@@ -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);
}
diff --git a/sys/dev/mlx/mlx.c b/sys/dev/mlx/mlx.c
index 58eb71b..6d9c49b 100644
--- a/sys/dev/mlx/mlx.c
+++ b/sys/dev/mlx/mlx.c
@@ -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";
diff --git a/sys/dev/mxge/if_mxge.c b/sys/dev/mxge/if_mxge.c
index f78b34b..8da11d7 100644
--- a/sys/dev/mxge/if_mxge.c
+++ b/sys/dev/mxge/if_mxge.c
@@ -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 {
diff --git a/sys/dev/nand/nand_id.c b/sys/dev/nand/nand_id.c
index 621e981..bf0b44a 100644
--- a/sys/dev/nand/nand_id.c
+++ b/sys/dev/nand/nand_id.c
@@ -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]);
diff --git a/sys/dev/ncr/ncr.c b/sys/dev/ncr/ncr.c
index 8cf142f..7a1c1d2 100644
--- a/sys/dev/ncr/ncr.c
+++ b/sys/dev/ncr/ncr.c
@@ -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 ||
diff --git a/sys/dev/nctgpio/nctgpio.c b/sys/dev/nctgpio/nctgpio.c
index ab547c0..ac2ac57 100644
--- a/sys/dev/nctgpio/nctgpio.c
+++ b/sys/dev/nctgpio/nctgpio.c
@@ -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) {
diff --git a/sys/dev/nfe/if_nfe.c b/sys/dev/nfe/if_nfe.c
index 58fee0b..d3accc5 100644
--- a/sys/dev/nfe/if_nfe.c
+++ b/sys/dev/nfe/if_nfe.c
@@ -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 &&
diff --git a/sys/dev/patm/if_patm_attach.c b/sys/dev/patm/if_patm_attach.c
index 29a2a87..8d936bb 100644
--- a/sys/dev/patm/if_patm_attach.c
+++ b/sys/dev/patm/if_patm_attach.c
@@ -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);
}
diff --git a/sys/dev/rc/rc.c b/sys/dev/rc/rc.c
index 1e8a23a..d600626 100644
--- a/sys/dev/rc/rc.c
+++ b/sys/dev/rc/rc.c
@@ -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;
diff --git a/sys/dev/re/if_re.c b/sys/dev/re/if_re.c
index 90bdffd..a5bc3be 100644
--- a/sys/dev/re/if_re.c
+++ b/sys/dev/re/if_re.c
@@ -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);
diff --git a/sys/dev/rl/if_rl.c b/sys/dev/rl/if_rl.c
index d9b7939..356da24 100644
--- a/sys/dev/rl/if_rl.c
+++ b/sys/dev/rl/if_rl.c
@@ -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);
diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c
index d2c43945..bd685f1 100644
--- a/sys/dev/sf/if_sf.c
+++ b/sys/dev/sf/if_sf.c
@@ -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);
diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c
index c27b7bc..60ba8b8 100644
--- a/sys/dev/sio/sio.c
+++ b/sys/dev/sio/sio.c
@@ -1638,7 +1638,7 @@ txrdy:
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;
diff --git a/sys/dev/sound/isa/gusc.c b/sys/dev/sound/isa/gusc.c
index bcb5957..239fd04 100644
--- a/sys/dev/sound/isa/gusc.c
+++ b/sys/dev/sound/isa/gusc.c
@@ -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;
diff --git a/sys/dev/speaker/spkr.c b/sys/dev/speaker/spkr.c
index 94d4792..ec890ff 100644
--- a/sys/dev/speaker/spkr.c
+++ b/sys/dev/speaker/spkr.c
@@ -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;
diff --git a/sys/dev/stge/if_stge.c b/sys/dev/stge/if_stge.c
index 0164eb8..1ebb05d 100644
--- a/sys/dev/stge/if_stge.c
+++ b/sys/dev/stge/if_stge.c
@@ -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);
diff --git a/sys/dev/vkbd/vkbd.c b/sys/dev/vkbd/vkbd.c
index fc5452a..6bfd5e9 100644
--- a/sys/dev/vkbd/vkbd.c
+++ b/sys/dev/vkbd/vkbd.c
@@ -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;
}
diff --git a/sys/dev/wbwd/wbwd.c b/sys/dev/wbwd/wbwd.c
index 75fbea4..7ed2d48 100644
--- a/sys/dev/wbwd/wbwd.c
+++ b/sys/dev/wbwd/wbwd.c
@@ -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;
OpenPOWER on IntegriCloud