Skip to content

Commit 397c657

Browse files
Omer Efratjmberg-intel
authored andcommitted
cfg80211: use BIT_ULL for NL80211_STA_INFO_* attribute types
The BIT macro uses unsigned long which some architectures handle as 32 bit and therefore might cause macro's shift to overflow when used on a value equals or larger than 32 (NL80211_STA_INFO_RX_DURATION and afterwards). Since 'filled' member in station_info changed to u64, BIT_ULL macro should be used with all NL80211_STA_INFO_* attribute types instead of BIT to prevent future possible bugs when one will use BIT macro for higher attributes by mistake. This commit cleans up all usages of BIT macro with the above field in cfg80211 by changing it to BIT_ULL instead. In addition, there are some places which don't use BIT nor BIT_ULL macros so align those as well. Signed-off-by: Omer Efrat <omer.efrat@tandemg.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent f0c0407 commit 397c657

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

net/wireless/nl80211.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,13 +4619,13 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
46194619

46204620
#define PUT_SINFO(attr, memb, type) do { \
46214621
BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4622-
if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4622+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
46234623
nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
46244624
sinfo->memb)) \
46254625
goto nla_put_failure; \
46264626
} while (0)
46274627
#define PUT_SINFO_U64(attr, memb) do { \
4628-
if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4628+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
46294629
nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
46304630
sinfo->memb, NL80211_STA_INFO_PAD)) \
46314631
goto nla_put_failure; \
@@ -4634,14 +4634,14 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
46344634
PUT_SINFO(CONNECTED_TIME, connected_time, u32);
46354635
PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
46364636

4637-
if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4638-
BIT(NL80211_STA_INFO_RX_BYTES64)) &&
4637+
if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
4638+
BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
46394639
nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
46404640
(u32)sinfo->rx_bytes))
46414641
goto nla_put_failure;
46424642

4643-
if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4644-
BIT(NL80211_STA_INFO_TX_BYTES64)) &&
4643+
if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
4644+
BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
46454645
nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
46464646
(u32)sinfo->tx_bytes))
46474647
goto nla_put_failure;
@@ -4661,24 +4661,24 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
46614661
default:
46624662
break;
46634663
}
4664-
if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
4664+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
46654665
if (!nl80211_put_signal(msg, sinfo->chains,
46664666
sinfo->chain_signal,
46674667
NL80211_STA_INFO_CHAIN_SIGNAL))
46684668
goto nla_put_failure;
46694669
}
4670-
if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
4670+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
46714671
if (!nl80211_put_signal(msg, sinfo->chains,
46724672
sinfo->chain_signal_avg,
46734673
NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
46744674
goto nla_put_failure;
46754675
}
4676-
if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
4676+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
46774677
if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
46784678
NL80211_STA_INFO_TX_BITRATE))
46794679
goto nla_put_failure;
46804680
}
4681-
if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
4681+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
46824682
if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
46834683
NL80211_STA_INFO_RX_BITRATE))
46844684
goto nla_put_failure;
@@ -4694,7 +4694,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
46944694
PUT_SINFO(PEER_PM, peer_pm, u32);
46954695
PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
46964696

4697-
if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
4697+
if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
46984698
bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
46994699
if (!bss_param)
47004700
goto nla_put_failure;
@@ -4713,7 +4713,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
47134713

47144714
nla_nest_end(msg, bss_param);
47154715
}
4716-
if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
4716+
if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
47174717
nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
47184718
sizeof(struct nl80211_sta_flag_update),
47194719
&sinfo->sta_flags))
@@ -10266,7 +10266,7 @@ static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
1026610266
if (err)
1026710267
return err;
1026810268

10269-
if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
10269+
if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
1027010270
wdev->cqm_config->last_rssi_event_value =
1027110271
(s8) sinfo.rx_beacon_signal_avg;
1027210272
}

net/wireless/wext-compat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ static int cfg80211_wext_giwrate(struct net_device *dev,
12781278
if (err)
12791279
return err;
12801280

1281-
if (!(sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)))
1281+
if (!(sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)))
12821282
return -EOPNOTSUPP;
12831283

12841284
rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
@@ -1320,7 +1320,7 @@ static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
13201320

13211321
switch (rdev->wiphy.signal_type) {
13221322
case CFG80211_SIGNAL_TYPE_MBM:
1323-
if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1323+
if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL)) {
13241324
int sig = sinfo.signal;
13251325
wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
13261326
wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
@@ -1334,7 +1334,7 @@ static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
13341334
break;
13351335
}
13361336
case CFG80211_SIGNAL_TYPE_UNSPEC:
1337-
if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1337+
if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL)) {
13381338
wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
13391339
wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
13401340
wstats.qual.level = sinfo.signal;
@@ -1347,9 +1347,9 @@ static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
13471347
}
13481348

13491349
wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1350-
if (sinfo.filled & BIT(NL80211_STA_INFO_RX_DROP_MISC))
1350+
if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC))
13511351
wstats.discard.misc = sinfo.rx_dropped_misc;
1352-
if (sinfo.filled & BIT(NL80211_STA_INFO_TX_FAILED))
1352+
if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))
13531353
wstats.discard.retries = sinfo.tx_failed;
13541354

13551355
return &wstats;

0 commit comments

Comments
 (0)