From 2f1668b9166f190ff38fb838a547b3d7d4721e7a Mon Sep 17 00:00:00 2001 From: proski Date: Wed, 28 Nov 2007 05:36:29 +0000 Subject: [PATCH] Standardize on ARRAY_SIZE, stop defining and undefining N ARRAY_SIZE is present in all kernel versions we support. Use it instead of other definitions. Define ARRAY_SIZE in the userspace tools as well. git-svn-id: http://madwifi-project.org/svn/madwifi/trunk@2988 0192ed92-7a03-0410-a25b-9323aeb14dbd --- ath/if_ath.c | 42 ++++++++++++----------------------- ath/if_ath_pci.c | 2 +- net80211/ieee80211.c | 12 +++------- net80211/ieee80211_crypto.c | 6 ++--- net80211/ieee80211_proto.c | 6 ++--- net80211/ieee80211_scan_ap.c | 4 +--- net80211/ieee80211_scan_sta.c | 8 +------ net80211/ieee80211_wireless.c | 8 +++---- regression/ccmp/test_ccmp.c | 4 +--- regression/wep/test_wep.c | 4 +--- tools/80211debug.c | 11 ++++----- tools/80211stats.c | 2 -- tools/ath_info.c | 6 +++-- tools/athdebug.c | 11 ++++----- tools/athstats.c | 9 ++++---- tools/wlanconfig.c | 8 +++---- 16 files changed, 54 insertions(+), 89 deletions(-) diff --git a/ath/if_ath.c b/ath/if_ath.c index fc8c806..6391f80 100644 --- a/ath/if_ath.c +++ b/ath/if_ath.c @@ -3392,7 +3392,6 @@ ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, const u_int8_t mac0[IEEE80211_ADDR_LEN], struct ieee80211_node *bss) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) static const u_int8_t ciphermap[] = { HAL_CIPHER_WEP, /* IEEE80211_CIPHER_WEP */ HAL_CIPHER_TKIP, /* IEEE80211_CIPHER_TKIP */ @@ -3415,7 +3414,7 @@ ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, * so that rx frames have an entry to match. */ if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) == 0) { - KASSERT(cip->ic_cipher < N(ciphermap), + KASSERT(cip->ic_cipher < ARRAY_SIZE(ciphermap), ("invalid cipher type %u", cip->ic_cipher)); hk.kv_type = ciphermap[cip->ic_cipher]; hk.kv_len = k->wk_keylen; @@ -3443,7 +3442,6 @@ ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), &hk, mac, AH_FALSE); } -#undef N } /* @@ -3453,13 +3451,12 @@ ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, static ieee80211_keyix_t key_alloc_2pair(struct ath_softc *sc) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) u_int i; ieee80211_keyix_t keyix; KASSERT(sc->sc_splitmic, ("key cache !split")); /* XXX could optimize */ - for (i = 0; i < N(sc->sc_keymap) / 4; i++) { + for (i = 0; i < ARRAY_SIZE(sc->sc_keymap) / 4; i++) { u_int8_t b = sc->sc_keymap[i]; if (b != 0xff) { /* @@ -3496,7 +3493,6 @@ key_alloc_2pair(struct ath_softc *sc) } DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__); return IEEE80211_KEYIX_NONE; -#undef N } /* @@ -3506,13 +3502,12 @@ key_alloc_2pair(struct ath_softc *sc) static ieee80211_keyix_t key_alloc_pair(struct ath_softc *sc) { -#define N(a) (sizeof(a)/sizeof(a[0])) u_int i; ieee80211_keyix_t keyix; KASSERT(!sc->sc_splitmic, ("key cache split")); /* XXX could optimize */ - for (i = 0; i < N(sc->sc_keymap)/4; i++) { + for (i = 0; i < ARRAY_SIZE(sc->sc_keymap)/4; i++) { u_int8_t b = sc->sc_keymap[i]; if (b != 0xff) { /* @@ -3543,7 +3538,6 @@ key_alloc_pair(struct ath_softc *sc) } DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__); return IEEE80211_KEYIX_NONE; -#undef N } /* @@ -3552,12 +3546,11 @@ key_alloc_pair(struct ath_softc *sc) static ieee80211_keyix_t key_alloc_single(struct ath_softc *sc) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) u_int i; ieee80211_keyix_t keyix; /* XXX: try i, i + 32, i + 64, i + 32 + 64 to minimize key pair conflicts */ - for (i = 0; i < N(sc->sc_keymap); i++) { + for (i = 0; i < ARRAY_SIZE(sc->sc_keymap); i++) { u_int8_t b = sc->sc_keymap[i]; if (b != 0xff) { /* @@ -3574,7 +3567,6 @@ key_alloc_single(struct ath_softc *sc) } DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of space\n", __func__); return IEEE80211_KEYIX_NONE; -#undef N } /* @@ -6361,7 +6353,6 @@ ath_grppoll_txq_update(struct ath_softc *sc, int period) static void ath_grppoll_txq_setup(struct ath_softc *sc, int qtype, int period) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) struct ath_hal *ah = sc->sc_ah; HAL_TXQ_INFO qi; int qnum; @@ -6383,9 +6374,10 @@ ath_grppoll_txq_setup(struct ath_softc *sc, int qtype, int period) qnum = ath_hal_setuptxqueue(ah, qtype, &qi); if (qnum == -1) return ; - if (qnum >= N(sc->sc_txq)) { + if (qnum >= ARRAY_SIZE(sc->sc_txq)) { printk("%s: HAL qnum %u out of range, max %u!\n", - DEV_NAME(sc->sc_dev), qnum, N(sc->sc_txq)); + DEV_NAME(sc->sc_dev), qnum, + (unsigned)ARRAY_SIZE(sc->sc_txq)); ath_hal_releasetxqueue(ah, qnum); return; } @@ -6403,8 +6395,6 @@ ath_grppoll_txq_setup(struct ath_softc *sc, int qtype, int period) txq->axq_compbufsz = compbufsz; txq->axq_compbufp = compbufp; ath_hal_resettxqueue(ah, txq->axq_qnum); /* push to h/w */ -#undef N - } /* @@ -6680,7 +6670,6 @@ bf_fail: static struct ath_txq * ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) struct ath_hal *ah = sc->sc_ah; HAL_TXQ_INFO qi; int qnum; @@ -6750,9 +6739,10 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) #endif return NULL; } - if (qnum >= N(sc->sc_txq)) { + if (qnum >= ARRAY_SIZE(sc->sc_txq)) { printk("%s: HAL qnum %u out of range, max %u!\n", - DEV_NAME(sc->sc_dev), qnum, N(sc->sc_txq)); + DEV_NAME(sc->sc_dev), qnum, + (unsigned)ARRAY_SIZE(sc->sc_txq)); #ifdef ATH_SUPERG_COMP if (compbuf) { bus_free_consistent(sc->sc_bdev, compbufsz, @@ -6779,7 +6769,6 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) sc->sc_txqsetup |= 1 << qnum; } return &sc->sc_txq[qnum]; -#undef N } /* @@ -6794,12 +6783,12 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) static int ath_tx_setup(struct ath_softc *sc, int ac, int haltype) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) struct ath_txq *txq; - if (ac >= N(sc->sc_ac2q)) { + if (ac >= ARRAY_SIZE(sc->sc_ac2q)) { printk("%s: AC %u out of range, max %u!\n", - DEV_NAME(sc->sc_dev), ac, (unsigned)N(sc->sc_ac2q)); + DEV_NAME(sc->sc_dev), ac, + (unsigned)ARRAY_SIZE(sc->sc_ac2q)); return 0; } txq = ath_txq_setup(sc, HAL_TX_QUEUE_DATA, haltype); @@ -6808,7 +6797,6 @@ ath_tx_setup(struct ath_softc *sc, int ac, int haltype) return 1; } else return 0; -#undef N } /* @@ -9320,7 +9308,6 @@ ath_rate_setup(struct net_device *dev, u_int mode) static void ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode) { -#define N(a) ((int)(sizeof(a)/sizeof(a[0]))) /* NB: on/off times from the Atheros NDIS driver, w/ permission */ static const struct { u_int rate; /* tx/rx 802.11 rate */ @@ -9364,7 +9351,7 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode) rt->info[ix].phy == IEEE80211_T_OFDM) sc->sc_hwmap[i].flags |= IEEE80211_RADIOTAP_F_SHORTPRE; /* setup blink rate table to avoid per-packet lookup */ - for (j = 0; j < N(blinkrates) - 1; j++) + for (j = 0; j < ARRAY_SIZE(blinkrates) - 1; j++) if (blinkrates[j].rate == sc->sc_hwmap[i].ieeerate) break; /* NB: this uses the last entry if the rate isn't found */ @@ -9382,7 +9369,6 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode) sc->sc_protrix = (mode == IEEE80211_MODE_11G ? 1 : 0); /* rate index used to send mgt frames */ sc->sc_minrateix = 0; -#undef N } #ifdef ATH_SUPERG_FF diff --git a/ath/if_ath_pci.c b/ath/if_ath_pci.c index 9c704bc..10b1348 100644 --- a/ath/if_ath_pci.c +++ b/ath/if_ath_pci.c @@ -217,7 +217,7 @@ ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* looking for device type from broken device id */ vdevice = id->device; - for (i = 0; i < (sizeof(ath_devidmap) / sizeof(ath_devidmap[0])); i++) { + for (i = 0; i < ARRAY_SIZE(ath_devidmap); i++) { if (id->device == ath_devidmap[i][0]) { vdevice = ath_devidmap[i][1]; break; diff --git a/net80211/ieee80211.c b/net80211/ieee80211.c index d961380..7ae6da7 100644 --- a/net80211/ieee80211.c +++ b/net80211/ieee80211.c @@ -1276,7 +1276,6 @@ EXPORT_SYMBOL(ieee80211_chan2mode); int ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode) { -#define N(a) (sizeof(a) / sizeof(a[0])) static const struct { u_int m; /* rate & mode */ u_int r; /* if_media rate */ @@ -1343,18 +1342,16 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m mask |= IFM_IEEE80211_11G; break; } - for (i = 0; i < N(rates); i++) + for (i = 0; i < ARRAY_SIZE(rates); i++) if (rates[i].m == mask) return rates[i].r; return IFM_AUTO; -#undef N } EXPORT_SYMBOL(ieee80211_rate2media); int ieee80211_media2rate(int mword) { -#define N(a) (sizeof(a) / sizeof(a[0])) static const int ieeerates[] = { -1, /* IFM_AUTO */ 0, /* IFM_MANUAL */ @@ -1382,9 +1379,8 @@ ieee80211_media2rate(int mword) 108, /* IFM_IEEE80211_OFDM54 */ 144, /* IFM_IEEE80211_OFDM72 */ }; - return IFM_SUBTYPE(mword) < N(ieeerates) ? + return IFM_SUBTYPE(mword) < ARRAY_SIZE(ieeerates) ? ieeerates[IFM_SUBTYPE(mword)] : 0; -#undef N } EXPORT_SYMBOL(ieee80211_media2rate); @@ -1473,7 +1469,6 @@ ieee80211_set_multicast_list(struct net_device *dev) void ieee80211_build_countryie(struct ieee80211com *ic) { -#define N(a) (sizeof (a) / sizeof (a[0])) int i, j, chanflags, found; struct net_device *dev = ic->ic_dev; struct ieee80211_channel *c; @@ -1488,7 +1483,7 @@ ieee80211_build_countryie(struct ieee80211com *ic) /* Initialize country IE */ found = 0; - for (i = 0; i < N(country_strings); i++) { + for (i = 0; i < ARRAY_SIZE(country_strings); i++) { if (country_strings[i].iso_code == ic->ic_country_code) { ic->ic_country_ie.country_str[0] = country_strings[i].iso_name[0]; ic->ic_country_ie.country_str[1] = country_strings[i].iso_name[1]; @@ -1608,7 +1603,6 @@ ieee80211_build_countryie(struct ieee80211com *ic) ic->ic_country_ie.country_triplet[1] = 11; ic->ic_country_ie.country_triplet[2] = 12; #endif -#undef N } int ath_debug_global = 0; diff --git a/net80211/ieee80211_crypto.c b/net80211/ieee80211_crypto.c index 1c65774..f7949f8 100644 --- a/net80211/ieee80211_crypto.c +++ b/net80211/ieee80211_crypto.c @@ -252,7 +252,6 @@ static const char *cipher_modnames[] = { int ieee80211_crypto_available(struct ieee80211vap *vap, u_int cipher) { -#define N(a) (sizeof(a) / sizeof(a[0])) unsigned int status = 0; if (cipher < IEEE80211_CIPHER_MAX) { @@ -263,7 +262,7 @@ ieee80211_crypto_available(struct ieee80211vap *vap, u_int cipher) * than numbers and craft a module name based on the cipher * name; e.g. wlan_cipher_. */ - if (cipher < N(cipher_modnames)) { + if (cipher < ARRAY_SIZE(cipher_modnames)) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "%s: unregistered cipher %u, load module %s\n", __func__, cipher, cipher_modnames[cipher]); @@ -278,7 +277,7 @@ ieee80211_crypto_available(struct ieee80211vap *vap, u_int cipher) IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "%s: unable to load cipher %u, module %s\n", __func__, cipher, - cipher < N(cipher_modnames) ? + cipher < ARRAY_SIZE(cipher_modnames) ? cipher_modnames[cipher] : ""); vap->iv_stats.is_crypto_nocipher++; } else @@ -288,7 +287,6 @@ ieee80211_crypto_available(struct ieee80211vap *vap, u_int cipher) status = 1; } return status; -#undef N } EXPORT_SYMBOL(ieee80211_crypto_available); diff --git a/net80211/ieee80211_proto.c b/net80211/ieee80211_proto.c index d692510..292906a 100644 --- a/net80211/ieee80211_proto.c +++ b/net80211/ieee80211_proto.c @@ -554,13 +554,12 @@ ieee80211_set_shortslottime(struct ieee80211com *ic, int onoff) int ieee80211_iserp_rateset(struct ieee80211com *ic, struct ieee80211_rateset *rs) { -#define N(a) (sizeof(a) / sizeof(a[0])) static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 }; int i, j; - if (rs->rs_nrates < N(rates)) + if (rs->rs_nrates < ARRAY_SIZE(rates)) return 0; - for (i = 0; i < N(rates); i++) { + for (i = 0; i < ARRAY_SIZE(rates); i++) { for (j = 0; j < rs->rs_nrates; j++) { int r = rs->rs_rates[j] & IEEE80211_RATE_VAL; if (rates[i] == r) @@ -573,7 +572,6 @@ ieee80211_iserp_rateset(struct ieee80211com *ic, struct ieee80211_rateset *rs) ; } return 1; -#undef N } static const struct ieee80211_rateset basic11g[IEEE80211_MODE_MAX] = { diff --git a/net80211/ieee80211_scan_ap.c b/net80211/ieee80211_scan_ap.c index 5535674..a7a92db 100644 --- a/net80211/ieee80211_scan_ap.c +++ b/net80211/ieee80211_scan_ap.c @@ -201,12 +201,11 @@ add_channels(struct ieee80211com *ic, struct ieee80211_scan_state *ss, enum ieee80211_phymode mode, const u_int16_t freq[], int nfreq) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct ieee80211_channel *c, *cg; u_int modeflags; int i; - KASSERT(mode < N(chanflags), ("Unexpected mode %u", mode)); + KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode)); modeflags = chanflags[mode]; for (i = 0; i < nfreq; i++) { c = ieee80211_find_channel(ic, freq[i], modeflags); @@ -225,7 +224,6 @@ add_channels(struct ieee80211com *ic, break; ss->ss_chans[ss->ss_last++] = c; } -#undef N } /* This function must be invoked with locks acquired */ diff --git a/net80211/ieee80211_scan_sta.c b/net80211/ieee80211_scan_sta.c index c5e26df..f3aaa79 100644 --- a/net80211/ieee80211_scan_sta.c +++ b/net80211/ieee80211_scan_sta.c @@ -356,12 +356,11 @@ add_channels(struct ieee80211com *ic, struct ieee80211_scan_state *ss, enum ieee80211_phymode mode, const u_int16_t freq[], int nfreq) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct ieee80211_channel *c, *cg; u_int modeflags; int i; - KASSERT(mode < N(chanflags), ("Unexpected mode %u", mode)); + KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode)); modeflags = chanflags[mode]; for (i = 0; i < nfreq; i++) { c = ieee80211_find_channel(ic, freq[i], modeflags); @@ -380,7 +379,6 @@ add_channels(struct ieee80211com *ic, break; ss->ss_chans[ss->ss_last++] = c; } -#undef N } static const u_int16_t rcl1[] = /* 8 FCC channel: 52, 56, 60, 64, 36, 40, 44, 48 */ @@ -466,7 +464,6 @@ checktable(const struct scanlist *scan, const struct ieee80211_channel *c) static int sta_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) { -#define N(a) (sizeof(a)/sizeof(a[0])) struct ieee80211com *ic = vap->iv_ic; struct sta_table *st = ss->ss_priv; const struct scanlist *scan; @@ -560,7 +557,6 @@ sta_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) st->st_newscan = 1; return 0; -#undef N } /* @@ -1161,7 +1157,6 @@ static const struct ieee80211_scanner sta_default = { static int adhoc_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) { -#define N(a) (sizeof(a)/sizeof(a[0])) struct ieee80211com *ic = vap->iv_ic; struct sta_table *st = ss->ss_priv; const struct scanlist *scan; @@ -1227,7 +1222,6 @@ adhoc_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) st->st_newscan = 1; return 0; -#undef N } /* diff --git a/net80211/ieee80211_wireless.c b/net80211/ieee80211_wireless.c index b1889ee..394f0d2 100644 --- a/net80211/ieee80211_wireless.c +++ b/net80211/ieee80211_wireless.c @@ -5461,17 +5461,15 @@ static const iw_handler ieee80211_priv_handlers[] = { }; static struct iw_handler_def ieee80211_iw_handler_def = { -#define N(a) (sizeof (a) / sizeof (a[0])) .standard = (iw_handler *) ieee80211_handlers, - .num_standard = N(ieee80211_handlers), + .num_standard = ARRAY_SIZE(ieee80211_handlers), .private = (iw_handler *) ieee80211_priv_handlers, - .num_private = N(ieee80211_priv_handlers), + .num_private = ARRAY_SIZE(ieee80211_priv_handlers), .private_args = (struct iw_priv_args *) ieee80211_priv_args, - .num_private_args = N(ieee80211_priv_args), + .num_private_args = ARRAY_SIZE(ieee80211_priv_args), #if IW_HANDLER_VERSION >= 7 .get_wireless_stats = ieee80211_iw_getstats, #endif -#undef N }; /* diff --git a/regression/ccmp/test_ccmp.c b/regression/ccmp/test_ccmp.c index 3e06247..909bb28 100644 --- a/regression/ccmp/test_ccmp.c +++ b/regression/ccmp/test_ccmp.c @@ -713,7 +713,6 @@ MODULE_PARM_DESC(debug, "Enable IEEE80211_MSG_CRYPTO"); static int __init init_crypto_ccmp_test(void) { -#define N(a) (sizeof(a)/sizeof(a[0])) struct ieee80211com ic; struct ieee80211vap vap; int i, pass, total; @@ -728,7 +727,7 @@ init_crypto_ccmp_test(void) pass = 0; total = 0; - for (i = 0; i < N(ccmptests); i++) + for (i = 0; i < ARRAY_SIZE(ccmptests); i++) if (tests & (1 << i)) { total++; pass += runtest(&vap, &ccmptests[i]); @@ -737,7 +736,6 @@ init_crypto_ccmp_test(void) ieee80211_crypto_vdetach(&vap); ieee80211_crypto_detach(&ic); return (pass == total ? 0 : -ENXIO); -#undef N } module_init(init_crypto_ccmp_test); diff --git a/regression/wep/test_wep.c b/regression/wep/test_wep.c index 13b9279..6c6574f 100644 --- a/regression/wep/test_wep.c +++ b/regression/wep/test_wep.c @@ -317,7 +317,6 @@ MODULE_PARM_DESC(debug, "Enable IEEE80211_MSG_CRYPTO"); static int __init init_crypto_wep_test(void) { -#define N(a) (sizeof(a)/sizeof(a[0])) struct ieee80211com ic; struct ieee80211vap vap; int i, pass, total; @@ -331,7 +330,7 @@ init_crypto_wep_test(void) ieee80211_crypto_vattach(&vap); pass = 0; total = 0; - for (i = 0; i < N(weptests); i++) + for (i = 0; i < ARRAY_SIZE(weptests); i++) if (tests & (1 << i)) { total++; pass += runtest(&vap, &weptests[i]); @@ -340,7 +339,6 @@ init_crypto_wep_test(void) ieee80211_crypto_vdetach(&vap); ieee80211_crypto_detach(&ic); return (pass == total ? 0 : -ENXIO); -#undef N } module_init(init_crypto_wep_test); diff --git a/tools/80211debug.c b/tools/80211debug.c index 734ef96..fef7037 100644 --- a/tools/80211debug.c +++ b/tools/80211debug.c @@ -49,7 +49,8 @@ #include #include -#define N(a) (sizeof(a)/sizeof(a[0])) +#undef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) static const char *progname; @@ -122,7 +123,7 @@ getflag(const char *name, int len) { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (strncasecmp(flags[i].name, name, len) == 0) return flags[i].bit; return 0; @@ -135,7 +136,7 @@ usage(void) fprintf(stderr, "usage: %s [-i interface] [(+/-) flags]\n", progname); fprintf(stderr, "\twhere flags are:\n\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) printf("\t%12s\t0x%08x\t%s\n", flags[i].name, flags[i].bit, flags[i].desc); exit(-1); } @@ -259,14 +260,14 @@ main(int argc, char *argv[]) } else printf("%s: 0x%08x", oid, debug); sep = "<"; - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (debug & flags[i].bit) { printf("%s%s", sep, flags[i].name); sep = ","; } printf("%s\n", *sep != '<' ? ">" : ""); printf("Details:\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) printf("%12s %s 0x%08x - %s\n", flags[i].name, debug & flags[i].bit ? "+" : " ", flags[i].bit, flags[i].desc); return 0; } diff --git a/tools/80211stats.c b/tools/80211stats.c index 49ed85e..8cf8660 100644 --- a/tools/80211stats.c +++ b/tools/80211stats.c @@ -74,7 +74,6 @@ static void printstats(FILE *fd, const struct ieee80211_stats *stats) { -#define N(a) (sizeof(a) / sizeof(a[0])) #define STAT(x,fmt) \ if (stats->is_##x) fprintf(fd, "%u " fmt "\n", stats->is_##x) STAT(rx_badversion, "rx frame with bad version"); @@ -158,7 +157,6 @@ printstats(FILE *fd, const struct ieee80211_stats *stats) STAT(crypto_swfallback, "crypto fell back to s/w implementation"); STAT(crypto_keyfail, "setkey failed due to driver key alloc failed"); #undef STAT -#undef N } static struct ifreq ifr; diff --git a/tools/ath_info.c b/tools/ath_info.c index 3999bea..5edbd3a 100644 --- a/tools/ath_info.c +++ b/tools/ath_info.c @@ -99,6 +99,9 @@ #include #include +#undef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #define dbg(fmt, __args__...) \ do { \ if (verbose) \ @@ -109,7 +112,6 @@ do { \ fprintf(stderr, "#ERR %s: " fmt "\n", __FUNCTION__, ##__args__) #define AR5K_PCI_MEM_SIZE 0x10000 -#define AR5K_ELEMENTS(_array) (sizeof(_array) / sizeof(_array[0])) #define AR5K_NUM_GPIO 6 @@ -534,7 +536,7 @@ static const char *ath5k_hw_get_part_name(enum ath5k_srev_type type, const char *name = "xxxxx"; int i; - for (i = 0; i < AR5K_ELEMENTS(ath5k_srev_names); i++) { + for (i = 0; i < ARRAY_SIZE(ath5k_srev_names); i++) { if (ath5k_srev_names[i].sr_type != type || ath5k_srev_names[i].sr_val == AR5K_SREV_UNKNOWN) continue; diff --git a/tools/athdebug.c b/tools/athdebug.c index 4549e5a..947bcbb 100644 --- a/tools/athdebug.c +++ b/tools/athdebug.c @@ -52,7 +52,8 @@ #include #include -#define N(a) (sizeof(a)/sizeof(a[0])) +#undef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) static const char *progname; @@ -129,7 +130,7 @@ getflag(const char *name, int len) { int i; - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (strncasecmp(flags[i].name, name, len) == 0) return flags[i].bit; return 0; @@ -142,7 +143,7 @@ usage(void) fprintf(stderr, "usage: %s [-i device] [(+/-) flags]\n", progname); fprintf(stderr, "\twhere flags are:\n\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) printf("\t%12s\t0x%08x\t%s\n", flags[i].name, flags[i].bit, flags[i].desc); exit(-1); } @@ -271,14 +272,14 @@ main(int argc, char *argv[]) } else printf("%s: 0x%08x", oid, debug); sep = "<"; - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (debug & flags[i].bit) { printf("%s%s", sep, flags[i].name); sep = ","; } printf("%s\n", *sep != '<' ? ">" : ""); printf("Details:\n"); - for (i = 0; i < N(flags); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) printf("%12s %s 0x%08x - %s\n", flags[i].name, debug & flags[i].bit ? "+" : " ", flags[i].bit, flags[i].desc); return 0; } diff --git a/tools/athstats.c b/tools/athstats.c index 9e7fc4d..a244a86 100644 --- a/tools/athstats.c +++ b/tools/athstats.c @@ -63,6 +63,9 @@ #include "wireless_copy.h" #include "if_athioctl.h" +#undef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + static const struct { u_int phyerr; const char* desc; @@ -91,7 +94,6 @@ static const struct { static void printstats(FILE *fd, const struct ath_stats *stats) { -#define N(a) (sizeof(a) / sizeof(a[0])) #define STAT(x,fmt) \ if (stats->ast_##x) fprintf(fd, "%u " fmt "\n", stats->ast_##x) #define STATI(x,fmt) \ @@ -138,10 +140,10 @@ printstats(FILE *fd, const struct ath_stats *stats) for (i = 0; i < 32; i++) { if (stats->ast_rx_phy[i] == 0) continue; - for (j = 0; j < N(phyerrdescriptions); j++) + for (j = 0; j < ARRAY_SIZE(phyerrdescriptions); j++) if (phyerrdescriptions[j].phyerr == i) break; - if (j == N(phyerrdescriptions)) + if (j == ARRAY_SIZE(phyerrdescriptions)) fprintf(fd, " %u (unknown phy error code %u)\n", stats->ast_rx_phy[i], i); @@ -172,7 +174,6 @@ printstats(FILE *fd, const struct ath_stats *stats) stats->ast_ant_tx[i], stats->ast_ant_rx[i]); #undef STAT #undef STATI -#undef N } static u_int diff --git a/tools/wlanconfig.c b/tools/wlanconfig.c index a7676c3..360a261 100644 --- a/tools/wlanconfig.c +++ b/tools/wlanconfig.c @@ -74,6 +74,9 @@ #define streq(a,b) (strncasecmp(a, b, sizeof(b) - 1) == 0) +#undef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + static int if_split_name(const char *, char **, unsigned int *); static void vap_create(struct ifreq *); static void vap_destroy(const char *); @@ -925,8 +928,6 @@ get80211param(const char *ifname, int param, void *data, size_t len) static int do80211priv(struct iwreq *iwr, const char *ifname, int op, void *data, size_t len) { -#define N(a) (sizeof(a)/sizeof(a[0])) - memset(iwr, 0, sizeof(struct iwreq)); strncpy(iwr->ifr_name, ifname, IFNAMSIZ); if (len < IFNAMSIZ) { @@ -970,14 +971,13 @@ do80211priv(struct iwreq *iwr, const char *ifname, int op, void *data, size_t le IOCTL_ERR(IEEE80211_IOCTL_WRITEREG), }; op -= SIOCIWFIRSTPRIV; - if (0 <= op && op < N(opnames)) + if (0 <= op && op < ARRAY_SIZE(opnames)) perror(opnames[op]); else perror("ioctl[unknown???]"); return -1; } return 0; -#undef N } static int -- 2.35.1