* [PATCHv2 ath-next] wifi: ath12k: use kzalloc_flex
@ 2026-04-21 21:35 Rosen Penev
2026-04-22 7:33 ` Rameshkumar Sundaram
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-04-21 21:35 UTC (permalink / raw)
To: linux-wireless
Cc: Jeff Johnson, Kees Cook, Gustavo A. R. Silva,
open list:QUALCOMM ATH12K WIRELESS DRIVER, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
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>
---
v2: reword last comment.
drivers/net/wireless/ath/ath12k/mac.c | 29 +++++++--------------------
drivers/net/wireless/ath/ath12k/wmi.h | 2 +-
2 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
index fbdfe6424fd7..32d590504a80 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -5611,12 +5611,14 @@ static int ath12k_mac_initiate_hw_scan(struct ieee80211_hw *hw,
if (ret)
goto exit;
- arg = kzalloc_obj(*arg);
+ arg = kzalloc_flex(*arg, chan_list, n_channels);
if (!arg) {
ret = -ENOMEM;
goto exit;
}
+ arg->num_chan = n_channels;
+
ath12k_wmi_start_scan_init(ar, arg);
arg->vdev_id = arvif->vdev_id;
arg->scan_id = ATH12K_SCAN_ID;
@@ -5638,18 +5640,8 @@ static int ath12k_mac_initiate_hw_scan(struct ieee80211_hw *hw,
arg->scan_f_passive = 1;
}
- if (n_channels) {
- arg->num_chan = n_channels;
- arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list),
- GFP_KERNEL);
- if (!arg->chan_list) {
- ret = -ENOMEM;
- goto exit;
- }
-
- for (i = 0; i < arg->num_chan; i++)
- arg->chan_list[i] = chan_list[i]->center_freq;
- }
+ for (i = 0; i < arg->num_chan; i++)
+ arg->chan_list[i] = chan_list[i]->center_freq;
ret = ath12k_start_scan(ar, arg);
if (ret) {
@@ -5674,7 +5666,6 @@ static int ath12k_mac_initiate_hw_scan(struct ieee80211_hw *hw,
exit:
if (arg) {
- kfree(arg->chan_list);
kfree(arg->extraie.ptr);
kfree(arg);
}
@@ -13735,19 +13726,13 @@ int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
scan_time_msec = hw->wiphy->max_remain_on_channel_duration * 2;
struct ath12k_wmi_scan_req_arg *arg __free(kfree) =
- kzalloc_obj(*arg);
+ kzalloc_flex(*arg, chan_list, 1);
if (!arg)
return -ENOMEM;
- ath12k_wmi_start_scan_init(ar, arg);
arg->num_chan = 1;
+ ath12k_wmi_start_scan_init(ar, arg);
- u32 *chan_list __free(kfree) = kcalloc(arg->num_chan, sizeof(*chan_list),
- GFP_KERNEL);
- if (!chan_list)
- return -ENOMEM;
-
- arg->chan_list = chan_list;
arg->vdev_id = arvif->vdev_id;
arg->scan_id = ATH12K_SCAN_ID;
arg->chan_list[0] = chan->center_freq;
diff --git a/drivers/net/wireless/ath/ath12k/wmi.h b/drivers/net/wireless/ath/ath12k/wmi.h
index 5ba9b7d3a888..5f150f21c146 100644
--- a/drivers/net/wireless/ath/ath12k/wmi.h
+++ b/drivers/net/wireless/ath/ath12k/wmi.h
@@ -3586,7 +3586,6 @@ struct ath12k_wmi_scan_req_arg {
u32 num_bssid;
u32 num_ssids;
u32 n_probes;
- u32 *chan_list;
u32 notify_scan_events;
struct cfg80211_ssid ssid[WLAN_SCAN_MAX_NUM_SSID];
struct ath12k_wmi_mac_addr_params bssid_list[WLAN_SCAN_MAX_NUM_BSSID];
@@ -3595,6 +3594,7 @@ struct ath12k_wmi_scan_req_arg {
u32 num_hint_bssid;
struct ath12k_wmi_hint_short_ssid_arg hint_s_ssid[WLAN_SCAN_MAX_HINT_S_SSID];
struct ath12k_wmi_hint_bssid_arg hint_bssid[WLAN_SCAN_MAX_HINT_BSSID];
+ u32 chan_list[] __counted_by(num_chan);
};
struct wmi_ssid_arg {
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv2 ath-next] wifi: ath12k: use kzalloc_flex
2026-04-21 21:35 [PATCHv2 ath-next] wifi: ath12k: use kzalloc_flex Rosen Penev
@ 2026-04-22 7:33 ` Rameshkumar Sundaram
0 siblings, 0 replies; 2+ messages in thread
From: Rameshkumar Sundaram @ 2026-04-22 7:33 UTC (permalink / raw)
To: Rosen Penev, linux-wireless
Cc: Jeff Johnson, Kees Cook, Gustavo A. R. Silva,
open list:QUALCOMM ATH12K WIRELESS DRIVER, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On 4/22/2026 3:05 AM, Rosen Penev wrote:
> 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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-22 7:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 21:35 [PATCHv2 ath-next] wifi: ath12k: use kzalloc_flex Rosen Penev
2026-04-22 7:33 ` Rameshkumar Sundaram
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox