* [PATCH ath-next] wifi: ath12k: use kzalloc_flex
@ 2026-03-13 0:14 Rosen Penev
2026-04-21 2:53 ` Baochen Qiang
0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-03-13 0:14 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 as required by __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
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 553ec28b6aaa..b7c43a64e37b 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 0bf0a7941cd3..190e7a4a92d0 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] 3+ messages in thread* Re: [PATCH ath-next] wifi: ath12k: use kzalloc_flex
2026-03-13 0:14 [PATCH ath-next] wifi: ath12k: use kzalloc_flex Rosen Penev
@ 2026-04-21 2:53 ` Baochen Qiang
2026-04-21 5:44 ` Gustavo A. R. Silva
0 siblings, 1 reply; 3+ messages in thread
From: Baochen Qiang @ 2026-04-21 2:53 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 3/13/2026 8:14 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 as required by __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> 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 553ec28b6aaa..b7c43a64e37b 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 0bf0a7941cd3..190e7a4a92d0 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
>
>
Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH ath-next] wifi: ath12k: use kzalloc_flex
2026-04-21 2:53 ` Baochen Qiang
@ 2026-04-21 5:44 ` Gustavo A. R. Silva
0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2026-04-21 5:44 UTC (permalink / raw)
To: Baochen Qiang, 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/20/26 20:53, Baochen Qiang wrote:
>
>
> On 3/13/2026 8:14 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 as required by __counted_by.
Not true. This should be phrased differently[1]
-Gustavo
[1] https://lore.kernel.org/linux-hardening/37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com/
>>
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> 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 553ec28b6aaa..b7c43a64e37b 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 0bf0a7941cd3..190e7a4a92d0 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
>>
>>
>
> Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-21 5:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 0:14 [PATCH ath-next] wifi: ath12k: use kzalloc_flex Rosen Penev
2026-04-21 2:53 ` Baochen Qiang
2026-04-21 5:44 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox