From nobody Tue Apr 7 14:36:44 2026 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B394BCA6B for ; Fri, 13 Mar 2026 00:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773360989; cv=none; b=OdXS9+ZtyedL1jEuntIiQrvgIyPFIFDKlroKBuOpb/lw4amo4h7y3t5AQ6WRKm6Ywp1hV4RzVKD/AQrV+SHzpOd4ZhLDBgsIOxUWq4FIRpH7i1HQymC4gn8780Yoe0ifZANG6VX0XA0w3wVnOg7TDRNt1/rVmIy3DN+QQk+oet4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773360989; c=relaxed/simple; bh=RLLe8Nn4Adi81Y8GPo3Efcp1Ndv2LUmLZ/8xBbKDvVM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=P2Cj/eHl32i3Ptry0BgqcOpkH/VAKrD6EShfLBrqgPp+4wJgbsrkfa0zdg2hSg511/pOosDMgdgC/xBJBDKOL/FavVanE4Q52vHMXrczAP5ZIV4eEMfr5qsJSOBmm4SNGCHlqba44BEDIeIa8TscqWaFBjhjxgRdjKShUgMi9G8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JUvIHvPe; arc=none smtp.client-ip=74.125.224.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JUvIHvPe" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-64cb577e79cso1970164d50.0 for ; Thu, 12 Mar 2026 17:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773360987; x=1773965787; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=F3YA59Mp4HTuyJkhwuElaXOAlXnXSvbB0FwywcY2nbs=; b=JUvIHvPe5ofQwTps7zIgtv7hAsIj8ABsSvgTE3ec6jR3R8ug8j/mTZgbOGagu3/ZAj NRSMIZQ/xoGbDytpPEfnS01IIGiEjEuWYlXTUoPH7XKO1uSGCflewfSgzMpNj8G2BEWf sJdIGBL26ZQOJOcXOInOYjIyW6qMXSfbuPcCbMggiCCaeTKB0RH9xtbTwnyXb93RScCY uNQSiqgWOD73giAsKT39op4Cf9FuVgUIShECJAeIUIM8Hk4XsV+MmhaG+ufj4Ad0zBg4 lpDNjRj2e64PNCxsmkdS2KscBe53GNSScALX3Od4j14G9ZHGQllHimvFQZbEbk10VQA8 rhNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773360987; x=1773965787; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=F3YA59Mp4HTuyJkhwuElaXOAlXnXSvbB0FwywcY2nbs=; b=KdDXS4ZqHd/iU6rkpmdC8FJRnRMiVlHgZ5DNWpplYSC1zTZ3Fh78VNPzF7IoFuWTrQ 2c0tKzEvLAZ4Rs2D03jSRAbhm9HikVFKUZCkgWDMfgHG+dSQQuc6eOFjmdKNoupGiu3J bgGg0Kwu5Vk7MZbrAPodnKkMjmg1IoJ8QJYRMdT5QKm5b1au5/IrjC/aR0IKfStIyj3Y cH7ngHUpXf9qg38B8Yjj/BfnU1QcKaDvoDsl/+zeNtGy3AAJv2hdN37EvI7D5/smQM+u zEWKNy7JluqIdgWed6BNjC7tX9YFWX3brKpgcUgzdyddtjIUoTA5lqXXngCIIvuZIw+C VSbw== X-Forwarded-Encrypted: i=1; AJvYcCUllgRiyfY/lYPlCeAbV0o0SJlAjcP/MjQOvnDZrmWOz/k5nbsa/co3pvQ3dvEb7g7lTXDdwPrrjv3wXvk=@vger.kernel.org X-Gm-Message-State: AOJu0YzW/vT88ab2OaJUbAZDykwx1F0c4ZCRWKPu3+Z9eYyj42664m7l NMPJYJOG0WPHi74zOa/7xssuqTTh5s5+PXN3owziVFSqkuJN09FFJvZq X-Gm-Gg: ATEYQzzdD1pUx/AYz+VqLTLN0FKBP1BIzN47yKD7N6aHJ6RcRLmfUF6knlJc5mOK2JF BfMJzyLiluDbSXwuUzt1BkzZx/PAmXqWHFd5UJ3mUZyOWU0K7xoU7vIsLbJ3ZU81Y/7G8/e5QbY Stw6tsYOl58HxXjM0/0nnMg11Tv/KQn3h3VIsO/f9akfj0BRZngw56ScrIn/D9AM6jSF7u7+9EW J0fp0Lejbkpgv2nR7YXfM5ONjbC3ohQX+DYSYSu1T7Nm3ke9cXS8jNpHBaq3aPu+ib+0d8Q2vdz ZOi84qQjH1gGGswBgVVOCr71OckYVsKTreoQnch1lel7CztpSIkjUZ9oYFyL0w5T8DtZgA7rnzH xchFJTM+LXXD+mtY3QGM/bQlcbUo75zPpg9ugGZR9HXJ65DqkdizMTYOMfGF7+3pSAcCr1mxOHV mWec8eNBxfDD+wTaBpP429pYBU7BAqG1eLWOseK75JJBmsK/f/y+n8og== X-Received: by 2002:a53:c448:0:b0:64c:9fd7:676a with SMTP id 956f58d0204a3-64e630dc827mr1182932d50.83.1773360986740; Thu, 12 Mar 2026 17:16:26 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64e65a405c5sm157460d50.2.2026.03.12.17.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 17:16:26 -0700 (PDT) From: Rosen Penev To: linux-wireless@vger.kernel.org Cc: Jeff Johnson , Kees Cook , "Gustavo A. R. Silva" , ath11k@lists.infradead.org (open list:QUALCOMM ATHEROS ATH11K WIRELESS DRIVER), linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH ath-next] wifi: ath11k: use kzalloc_flex Date: Thu, 12 Mar 2026 17:16:08 -0700 Message-ID: <20260313001608.118294-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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/a= th/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_h= w *hw, if (ret) goto exit; - arg =3D kzalloc_obj(*arg); + arg =3D kzalloc_flex(*arg, chan_list, req->n_channels); if (!arg) { ret =3D -ENOMEM; goto exit; } + arg->num_chan =3D req->n_channels; ath11k_wmi_start_scan_init(ar, arg); arg->vdev_id =3D arvif->vdev_id; arg->scan_id =3D ATH11K_SCAN_ID; @@ -4262,38 +4263,27 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_h= w *hw, arg->scan_f_passive =3D 1; } - if (req->n_channels) { - arg->num_chan =3D req->n_channels; - arg->chan_list =3D kcalloc(arg->num_chan, sizeof(*arg->chan_list), - GFP_KERNEL); + for (i =3D 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] =3D + u32_encode_bits(req->channels[i]->center_freq, + WMI_SCAN_CONFIG_PER_CHANNEL_MASK); - if (!arg->chan_list) { - ret =3D -ENOMEM; - goto exit; - } - - for (i =3D 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] =3D - 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 =3D=3D NL80211_BAND_6GHZ && - req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ && - !cfg80211_channel_is_psc(req->channels[i])) - arg->chan_list[i] |=3D - WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND; - } else { - arg->chan_list[i] =3D 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 =3D=3D NL80211_BAND_6GHZ && + req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ && + !cfg80211_channel_is_psc(req->channels[i])) + arg->chan_list[i] |=3D + WMI_SCAN_CH_FLAG_SCAN_ONLY_IF_RNR_FOUND; + } else { + arg->chan_list[i] =3D req->channels[i]->center_freq; } } @@ -9736,19 +9726,14 @@ static int ath11k_mac_op_remain_on_channel(struct i= eee80211_hw *hw, scan_time_msec =3D ar->hw->wiphy->max_remain_on_channel_duration * 2; - arg =3D kzalloc_obj(*arg); + arg =3D kzalloc_flex(*arg, chan_list, 1); if (!arg) { ret =3D -ENOMEM; goto exit; } - ath11k_wmi_start_scan_init(ar, arg); + arg->num_chan =3D 1; - arg->chan_list =3D kcalloc(arg->num_chan, sizeof(*arg->chan_list), - GFP_KERNEL); - if (!arg->chan_list) { - ret =3D -ENOMEM; - goto free_arg; - } + ath11k_wmi_start_scan_init(ar, arg); arg->vdev_id =3D arvif->vdev_id; arg->scan_id =3D ATH11K_SCAN_ID; @@ -9769,7 +9754,7 @@ static int ath11k_mac_op_remain_on_channel(struct iee= e80211_hw *hw, spin_lock_bh(&ar->data_lock); ar->scan.state =3D ATH11K_SCAN_IDLE; spin_unlock_bh(&ar->data_lock); - goto free_chan_list; + goto free_arg; } ret =3D wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); @@ -9779,7 +9764,7 @@ static int ath11k_mac_op_remain_on_channel(struct iee= e80211_hw *hw, if (ret) ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret); ret =3D -ETIMEDOUT; - goto free_chan_list; + goto free_arg; } ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, @@ -9787,8 +9772,6 @@ static int ath11k_mac_op_remain_on_channel(struct iee= e80211_hw *hw, ret =3D 0; -free_chan_list: - kfree(arg->chan_list); free_arg: kfree(arg); exit: diff --git a/drivers/net/wireless/ath/ath11k/wmi.h b/drivers/net/wireless/a= th/ath11k/wmi.h index baed501b640b..b2dade0516ac 100644 --- a/drivers/net/wireless/ath/ath11k/wmi.h +++ b/drivers/net/wireless/ath/ath11k/wmi.h @@ -3423,7 +3423,6 @@ struct scan_req_params { u32 num_bssid; u32 num_ssids; u32 n_probes; - u32 *chan_list; u32 notify_scan_events; struct wlan_ssid ssid[WLAN_SCAN_PARAMS_MAX_SSID]; struct wmi_mac_addr bssid_list[WLAN_SCAN_PARAMS_MAX_BSSID]; @@ -3436,6 +3435,7 @@ struct scan_req_params { struct hint_bssid hint_bssid[WLAN_SCAN_MAX_HINT_BSSID]; struct wmi_mac_addr mac_addr; struct wmi_mac_addr mac_mask; + u32 chan_list[] __counted_by(num_chan); }; struct wmi_ssid_arg { -- 2.53.0