From: Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com>
To: 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 ATHEROS ATH11K WIRELESS DRIVER"
<ath11k@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: [PATCHv2 ath-next] wifi: ath11k: use kzalloc_flex
Date: Tue, 28 Apr 2026 15:20:34 +0530 [thread overview]
Message-ID: <582155ff-1cac-4d88-a6b2-006146ba4e67@oss.qualcomm.com> (raw)
In-Reply-To: <20260421231205.77361-1-rosenp@gmail.com>
On 4/22/2026 4:42 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>
> ---
> v2: reword counting variable comment.
> drivers/net/wireless/ath/ath11k/mac.c | 71 ++++++++++-----------------
> drivers/net/wireless/ath/ath11k/wmi.h | 2 +-
> 2 files changed, 28 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
> index 4a68bb9ca4fa..b5f3d7221b5f 100644
> --- a/drivers/net/wireless/ath/ath11k/mac.c
> +++ b/drivers/net/wireless/ath/ath11k/mac.c
> @@ -4228,13 +4228,14 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
> if (ret)
> goto exit;
>
> - arg = kzalloc_obj(*arg);
> + arg = kzalloc_flex(*arg, chan_list, req->n_channels);
>
> if (!arg) {
> ret = -ENOMEM;
> goto exit;
> }
>
> + arg->num_chan = req->n_channels;
> ath11k_wmi_start_scan_init(ar, arg);
> arg->vdev_id = arvif->vdev_id;
> arg->scan_id = ATH11K_SCAN_ID;
> @@ -4262,38 +4263,27 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
> arg->scan_f_passive = 1;
> }
>
> - if (req->n_channels) {
> - arg->num_chan = req->n_channels;
> - arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list),
> - GFP_KERNEL);
> + for (i = 0; i < arg->num_chan; i++) {
> + if (test_bit(WMI_TLV_SERVICE_SCAN_CONFIG_PER_CHANNEL,
> + ar->ab->wmi_ab.svc_map)) {
> + arg->chan_list[i] =
> + u32_encode_bits(req->channels[i]->center_freq,
> + WMI_SCAN_CONFIG_PER_CHANNEL_MASK);
>
> - if (!arg->chan_list) {
> - ret = -ENOMEM;
> - goto exit;
> - }
> -
> - for (i = 0; i < arg->num_chan; i++) {
> - if (test_bit(WMI_TLV_SERVICE_SCAN_CONFIG_PER_CHANNEL,
> - ar->ab->wmi_ab.svc_map)) {
> - arg->chan_list[i] =
> - u32_encode_bits(req->channels[i]->center_freq,
> - WMI_SCAN_CONFIG_PER_CHANNEL_MASK);
> -
> - /* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is set in scan
> - * flags, then scan all PSC channels in 6 GHz band and
> - * those non-PSC channels where RNR IE is found during
> - * the legacy 2.4/5 GHz scan.
> - * If NL80211_SCAN_FLAG_COLOCATED_6GHZ is not set,
> - * then all channels in 6 GHz will be scanned.
> - */
> - if (req->channels[i]->band == NL80211_BAND_6GHZ &&
> - req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ &&
> - !cfg80211_channel_is_psc(req->channels[i]))
> - arg->chan_list[i] |=
> - WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND;
> - } else {
> - arg->chan_list[i] = req->channels[i]->center_freq;
> - }
> + /* If NL80211_SCAN_FLAG_COLOCATED_6GHZ is set in scan
> + * flags, then scan all PSC channels in 6 GHz band and
> + * those non-PSC channels where RNR IE is found during
> + * the legacy 2.4/5 GHz scan.
> + * If NL80211_SCAN_FLAG_COLOCATED_6GHZ is not set,
> + * then all channels in 6 GHz will be scanned.
> + */
> + if (req->channels[i]->band == NL80211_BAND_6GHZ &&
> + req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ &&
> + !cfg80211_channel_is_psc(req->channels[i]))
> + arg->chan_list[i] |=
> + WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND;
> + } else {
> + arg->chan_list[i] = req->channels[i]->center_freq;
> }
> }
>
the exit: label at the end of the function has kfree(arg->chan_list);
which now must be removed.
--
Ramesh
prev parent reply other threads:[~2026-04-28 9:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 23:12 [PATCHv2 ath-next] wifi: ath11k: use kzalloc_flex Rosen Penev
2026-04-28 2:37 ` Baochen Qiang
2026-04-28 9:50 ` Rameshkumar Sundaram [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=582155ff-1cac-4d88-a6b2-006146ba4e67@oss.qualcomm.com \
--to=rameshkumar.sundaram@oss.qualcomm.com \
--cc=ath11k@lists.infradead.org \
--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