Skip to content

Commit a1d9979

Browse files
committed
wifi: nl80211: make nl80211_check_scan_flags() type safe
The cast from void * here coupled with the boolean argument on what to cast to is confusing and really not needed, just split the code and make a type-safe interface. It seems to even reduce the code size slightly, at least on x86-64. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com> Link: https://patch.msgid.link/20250609213231.bdb3c96570b0.Ia153e6ce06dc9a636ff5bcc1d52468a1afd06e13@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent f0df91b commit a1d9979

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

net/wireless/nl80211.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9811,34 +9811,12 @@ static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
98119811

98129812
static int
98139813
nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
9814-
void *request, struct nlattr **attrs,
9815-
bool is_sched_scan)
9814+
struct nlattr **attrs, u8 *mac_addr, u8 *mac_addr_mask,
9815+
u32 *flags, enum nl80211_feature_flags randomness_flag)
98169816
{
9817-
u8 *mac_addr, *mac_addr_mask;
9818-
u32 *flags;
9819-
enum nl80211_feature_flags randomness_flag;
9820-
98219817
if (!attrs[NL80211_ATTR_SCAN_FLAGS])
98229818
return 0;
98239819

9824-
if (is_sched_scan) {
9825-
struct cfg80211_sched_scan_request *req = request;
9826-
9827-
randomness_flag = wdev ?
9828-
NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
9829-
NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
9830-
flags = &req->flags;
9831-
mac_addr = req->mac_addr;
9832-
mac_addr_mask = req->mac_addr_mask;
9833-
} else {
9834-
struct cfg80211_scan_request_int *req = request;
9835-
9836-
randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
9837-
flags = &req->req.flags;
9838-
mac_addr = req->req.mac_addr;
9839-
mac_addr_mask = req->req.mac_addr_mask;
9840-
}
9841-
98429820
*flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
98439821

98449822
if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
@@ -9887,6 +9865,30 @@ nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
98879865
return 0;
98889866
}
98899867

9868+
static int
9869+
nl80211_check_scan_flags_sched(struct wiphy *wiphy, struct wireless_dev *wdev,
9870+
struct nlattr **attrs,
9871+
struct cfg80211_sched_scan_request *req)
9872+
{
9873+
return nl80211_check_scan_flags(wiphy, wdev, attrs,
9874+
req->mac_addr, req->mac_addr_mask,
9875+
&req->flags,
9876+
wdev ? NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
9877+
NL80211_FEATURE_ND_RANDOM_MAC_ADDR);
9878+
}
9879+
9880+
static int
9881+
nl80211_check_scan_flags_reg(struct wiphy *wiphy, struct wireless_dev *wdev,
9882+
struct nlattr **attrs,
9883+
struct cfg80211_scan_request_int *req)
9884+
{
9885+
return nl80211_check_scan_flags(wiphy, wdev, attrs,
9886+
req->req.mac_addr,
9887+
req->req.mac_addr_mask,
9888+
&req->req.flags,
9889+
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR);
9890+
}
9891+
98909892
static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
98919893
{
98929894
struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -10083,8 +10085,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
1008310085
nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
1008410086
}
1008510087

10086-
err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
10087-
false);
10088+
err = nl80211_check_scan_flags_reg(wiphy, wdev, info->attrs, request);
1008810089
if (err)
1008910090
goto out_free;
1009010091

@@ -10537,7 +10538,7 @@ nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
1053710538
request->ie_len);
1053810539
}
1053910540

10540-
err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
10541+
err = nl80211_check_scan_flags_sched(wiphy, wdev, attrs, request);
1054110542
if (err)
1054210543
goto out_free;
1054310544

0 commit comments

Comments
 (0)