Skip to content

Commit c7427f2

Browse files
nehebjeff-t-johnson
authored andcommitted
wifi: ath11k: use kzalloc_flex for struct scan_req_params
Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation. Add __counted_by to get extra runtime analysis. Move counting variable assignment immediately after allocation before any potential accesses. kzalloc_flex does this anyway for GCC >= 15. Signed-off-by: Rosen Penev <rosenp@gmail.com> Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com> Reviewed-by: Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com> Link: https://patch.msgid.link/20260428205017.26288-1-rosenp@gmail.com Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
1 parent e7d6bd2 commit c7427f2

2 files changed

Lines changed: 28 additions & 46 deletions

File tree

drivers/net/wireless/ath/ath11k/mac.c

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,13 +4227,14 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
42274227
if (ret)
42284228
goto exit;
42294229

4230-
arg = kzalloc_obj(*arg);
4230+
arg = kzalloc_flex(*arg, chan_list, req->n_channels);
42314231

42324232
if (!arg) {
42334233
ret = -ENOMEM;
42344234
goto exit;
42354235
}
42364236

4237+
arg->num_chan = req->n_channels;
42374238
ath11k_wmi_start_scan_init(ar, arg);
42384239
arg->vdev_id = arvif->vdev_id;
42394240
arg->scan_id = ATH11K_SCAN_ID;
@@ -4261,38 +4262,27 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
42614262
arg->scan_f_passive = 1;
42624263
}
42634264

4264-
if (req->n_channels) {
4265-
arg->num_chan = req->n_channels;
4266-
arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list),
4267-
GFP_KERNEL);
4265+
for (i = 0; i < arg->num_chan; i++) {
4266+
if (test_bit(WMI_TLV_SERVICE_SCAN_CONFIG_PER_CHANNEL,
4267+
ar->ab->wmi_ab.svc_map)) {
4268+
arg->chan_list[i] =
4269+
u32_encode_bits(req->channels[i]->center_freq,
4270+
WMI_SCAN_CONFIG_PER_CHANNEL_MASK);
42684271

4269-
if (!arg->chan_list) {
4270-
ret = -ENOMEM;
4271-
goto exit;
4272-
}
4273-
4274-
for (i = 0; i < arg->num_chan; i++) {
4275-
if (test_bit(WMI_TLV_SERVICE_SCAN_CONFIG_PER_CHANNEL,
4276-
ar->ab->wmi_ab.svc_map)) {
4277-
arg->chan_list[i] =
4278-
u32_encode_bits(req->channels[i]->center_freq,
4279-
WMI_SCAN_CONFIG_PER_CHANNEL_MASK);
4280-
4281-
/* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is set in scan
4282-
* flags, then scan all PSC channels in 6 GHz band and
4283-
* those non-PSC channels where RNR IE is found during
4284-
* the legacy 2.4/5 GHz scan.
4285-
* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is not set,
4286-
* then all channels in 6 GHz will be scanned.
4287-
*/
4288-
if (req->channels[i]->band == NL80211_BAND_6GHZ &&
4289-
req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ &&
4290-
!cfg80211_channel_is_psc(req->channels[i]))
4291-
arg->chan_list[i] |=
4292-
WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND;
4293-
} else {
4294-
arg->chan_list[i] = req->channels[i]->center_freq;
4295-
}
4272+
/* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is set in scan
4273+
* flags, then scan all PSC channels in 6 GHz band and
4274+
* those non-PSC channels where RNR IE is found during
4275+
* the legacy 2.4/5 GHz scan.
4276+
* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is not set,
4277+
* then all channels in 6 GHz will be scanned.
4278+
*/
4279+
if (req->channels[i]->band == NL80211_BAND_6GHZ &&
4280+
req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ &&
4281+
!cfg80211_channel_is_psc(req->channels[i]))
4282+
arg->chan_list[i] |=
4283+
WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND;
4284+
} else {
4285+
arg->chan_list[i] = req->channels[i]->center_freq;
42964286
}
42974287
}
42984288

@@ -4335,7 +4325,6 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
43354325

43364326
exit:
43374327
if (arg) {
4338-
kfree(arg->chan_list);
43394328
kfree(arg->extraie.ptr);
43404329
kfree(arg);
43414330
}
@@ -9735,19 +9724,14 @@ static int ath11k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
97359724

97369725
scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
97379726

9738-
arg = kzalloc_obj(*arg);
9727+
arg = kzalloc_flex(*arg, chan_list, 1);
97399728
if (!arg) {
97409729
ret = -ENOMEM;
97419730
goto exit;
97429731
}
9743-
ath11k_wmi_start_scan_init(ar, arg);
9732+
97449733
arg->num_chan = 1;
9745-
arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list),
9746-
GFP_KERNEL);
9747-
if (!arg->chan_list) {
9748-
ret = -ENOMEM;
9749-
goto free_arg;
9750-
}
9734+
ath11k_wmi_start_scan_init(ar, arg);
97519735

97529736
arg->vdev_id = arvif->vdev_id;
97539737
arg->scan_id = ATH11K_SCAN_ID;
@@ -9768,7 +9752,7 @@ static int ath11k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
97689752
spin_lock_bh(&ar->data_lock);
97699753
ar->scan.state = ATH11K_SCAN_IDLE;
97709754
spin_unlock_bh(&ar->data_lock);
9771-
goto free_chan_list;
9755+
goto free_arg;
97729756
}
97739757

97749758
ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
@@ -9778,16 +9762,14 @@ static int ath11k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
97789762
if (ret)
97799763
ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
97809764
ret = -ETIMEDOUT;
9781-
goto free_chan_list;
9765+
goto free_arg;
97829766
}
97839767

97849768
ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
97859769
msecs_to_jiffies(duration));
97869770

97879771
ret = 0;
97889772

9789-
free_chan_list:
9790-
kfree(arg->chan_list);
97919773
free_arg:
97929774
kfree(arg);
97939775
exit:

drivers/net/wireless/ath/ath11k/wmi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,6 @@ struct scan_req_params {
34233423
u32 num_bssid;
34243424
u32 num_ssids;
34253425
u32 n_probes;
3426-
u32 *chan_list;
34273426
u32 notify_scan_events;
34283427
struct wlan_ssid ssid[WLAN_SCAN_PARAMS_MAX_SSID];
34293428
struct wmi_mac_addr bssid_list[WLAN_SCAN_PARAMS_MAX_BSSID];
@@ -3436,6 +3435,7 @@ struct scan_req_params {
34363435
struct hint_bssid hint_bssid[WLAN_SCAN_MAX_HINT_BSSID];
34373436
struct wmi_mac_addr mac_addr;
34383437
struct wmi_mac_addr mac_mask;
3438+
u32 chan_list[] __counted_by(num_chan);
34393439
};
34403440

34413441
struct wmi_ssid_arg {

0 commit comments

Comments
 (0)