From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Baochen Qiang <baochen.qiang@oss.qualcomm.com>,
Rosen Penev <rosenp@gmail.com>,
linux-wireless@vger.kernel.org
Cc: Jeff Johnson <jjohnson@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"open list:QUALCOMM ATH12K WIRELESS DRIVER"
<ath12k@lists.infradead.org>,
open list <linux-kernel@vger.kernel.org>,
open "list:KERNEL" HARDENING "(not" covered by other
"areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH ath-next] wifi: ath12k: use kzalloc_flex
Date: Mon, 20 Apr 2026 23:44:37 -0600 [thread overview]
Message-ID: <2650bb0e-804d-4858-a07f-c4190fb41038@embeddedor.com> (raw)
In-Reply-To: <a92cb332-b525-47f4-a529-a59080cb33dd@oss.qualcomm.com>
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>
>
>
prev parent reply other threads:[~2026-04-21 5:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2650bb0e-804d-4858-a07f-c4190fb41038@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=ath12k@lists.infradead.org \
--cc=baochen.qiang@oss.qualcomm.com \
--cc=gustavoars@kernel.org \
--cc=jjohnson@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=rosenp@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox