From 04bf19f2c237a3eeeb7adffb7855aaab2a6f61e3 Mon Sep 17 00:00:00 2001 From: jasper Date: Fri, 8 Aug 2014 15:16:39 +0000 Subject: [PATCH] use nitems() instead of various local constructs ok stsp@ --- sys/net80211/ieee80211.c | 14 ++++---------- sys/net80211/ieee80211_node.c | 6 ++---- sys/net80211/ieee80211_regdomain.c | 11 ++++------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c index cc2109c0510..41914e43364 100644 --- a/sys/net80211/ieee80211.c +++ b/sys/net80211/ieee80211.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211.c,v 1.40 2013/11/21 16:16:08 mpi Exp $ */ +/* $OpenBSD: ieee80211.c,v 1.41 2014/08/08 15:16:39 jasper Exp $ */ /* $NetBSD: ieee80211.c,v 1.19 2004/06/06 05:45:29 dyoung Exp $ */ /*- @@ -660,7 +660,6 @@ ieee80211_setbasicrates(struct ieee80211com *ic) int ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode) { -#define N(a) (sizeof(a) / sizeof(a[0])) struct ifnet *ifp = &ic->ic_if; static const u_int chanflags[] = { 0, /* IEEE80211_MODE_AUTO */ @@ -684,7 +683,7 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode) * Verify at least one channel is present in the available * channel list before committing to the new mode. */ - if (mode >= N(chanflags)) + if (mode >= nitems(chanflags)) panic("Unexpected mode %u", mode); modeflags = chanflags[mode]; for (i = 0; i <= IEEE80211_CHAN_MAX; i++) { @@ -747,7 +746,6 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode) ieee80211_reset_erp(ic); /* reset ERP state */ return 0; -#undef N } enum ieee80211_phymode @@ -826,7 +824,6 @@ 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 */ @@ -876,17 +873,15 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, mask |= IFM_IEEE80211_11G; break; } - for (i = 0; i < N(rates); i++) + for (i = 0; i < nitems(rates); i++) if (rates[i].m == mask) return rates[i].r; return IFM_AUTO; -#undef N } int ieee80211_media2rate(int mword) { -#define N(a) (sizeof(a) / sizeof(a[0])) int i; static const struct { int subtype; @@ -910,12 +905,11 @@ ieee80211_media2rate(int mword) { IFM_IEEE80211_OFDM54, 108 }, { IFM_IEEE80211_OFDM72, 144 }, }; - for (i = 0; i < N(ieeerates); i++) { + for (i = 0; i < nitems(ieeerates); i++) { if (ieeerates[i].subtype == IFM_SUBTYPE(mword)) return ieeerates[i].rate; } return 0; -#undef N } /* diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c index 3318a718a91..5829d0e33bb 100644 --- a/sys/net80211/ieee80211_node.c +++ b/sys/net80211/ieee80211_node.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_node.c,v 1.81 2014/07/12 18:44:22 tedu Exp $ */ +/* $OpenBSD: ieee80211_node.c,v 1.82 2014/08/08 15:16:39 jasper Exp $ */ /* $NetBSD: ieee80211_node.c,v 1.14 2004/05/09 09:18:47 dyoung Exp $ */ /*- @@ -1289,7 +1289,6 @@ ieee80211_setup_rates(struct ieee80211com *ic, struct ieee80211_node *ni, int ieee80211_iserp_sta(const struct ieee80211_node *ni) { -#define N(a) (sizeof (a) / sizeof (a)[0]) static const u_int8_t rates[] = { 2, 4, 11, 22, 12, 24, 48 }; const struct ieee80211_rateset *rs = &ni->ni_rates; int i, j; @@ -1298,7 +1297,7 @@ ieee80211_iserp_sta(const struct ieee80211_node *ni) * A STA supports ERP operation if it includes all the Clause 19 * mandatory rates in its supported rate set. */ - for (i = 0; i < N(rates); i++) { + for (i = 0; i < nitems(rates); i++) { for (j = 0; j < rs->rs_nrates; j++) { if ((rs->rs_rates[j] & IEEE80211_RATE_VAL) == rates[i]) break; @@ -1307,7 +1306,6 @@ ieee80211_iserp_sta(const struct ieee80211_node *ni) return 0; } return 1; -#undef N } /* diff --git a/sys/net80211/ieee80211_regdomain.c b/sys/net80211/ieee80211_regdomain.c index e6a64176b3f..c9d34b3d7be 100644 --- a/sys/net80211/ieee80211_regdomain.c +++ b/sys/net80211/ieee80211_regdomain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_regdomain.c,v 1.7 2006/11/26 19:46:28 deraadt Exp $ */ +/* $OpenBSD: ieee80211_regdomain.c,v 1.8 2014/08/08 15:16:39 jasper Exp $ */ /* * Copyright (c) 2004, 2005 Reyk Floeter @@ -101,8 +101,7 @@ ieee80211_name2countrycode(const char *name) const struct ieee80211_countryname key = { CTRY_DEFAULT, name }, *value; if ((value = bsearch(&key, &ieee80211_r_ctry, - sizeof(ieee80211_r_ctry) / sizeof(ieee80211_r_ctry[0]), - sizeof(struct ieee80211_countryname), + nitems(ieee80211_r_ctry), sizeof(struct ieee80211_countryname), ieee80211_regdomain_compare_cn)) != NULL) return (value->cn_code); @@ -119,8 +118,7 @@ ieee80211_name2regdomain(const char *name) key.rn_name = name; if ((value = bsearch(&key, &ieee80211_r_names, - sizeof(ieee80211_r_names) / sizeof(ieee80211_r_names[0]), - sizeof(struct ieee80211_regdomainname), + nitems(ieee80211_r_names), sizeof(struct ieee80211_regdomainname), ieee80211_regdomain_compare_rn)) != NULL) return ((u_int32_t)value->rn_domain); @@ -181,8 +179,7 @@ ieee80211_countrycode2regdomain(u_int16_t code) { int i; - for (i = 0; - i < (sizeof(ieee80211_r_ctry) / sizeof(ieee80211_r_ctry[0])); i++) + for (i = 0; i < nitems(ieee80211_r_ctry); i++) if (ieee80211_r_ctry[i].cn_code == code) return (ieee80211_r_ctry[i].cn_domain); -- 2.20.1