From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Len Baker <len.baker@gmx.com>
Cc: Kalle Valo <kvalo@codeaurora.org>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Kees Cook <keescook@chromium.org>,
ath11k@lists.infradead.org, linux-wireless@vger.kernel.org,
netdev@vger.kernel.org, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ath11k: Replace one-element array with flexible-array member
Date: Sun, 12 Sep 2021 14:31:40 -0500 [thread overview]
Message-ID: <20210912193140.GC146608@embeddedor> (raw)
In-Reply-To: <20210904114937.6644-1-len.baker@gmx.com>
There is already a patch for this:
https://lore.kernel.org/lkml/20210823172159.GA25800@embeddedor/
which I will now add to my -next tree.
Thanks
--
Gustavo
On Sat, Sep 04, 2021 at 01:49:37PM +0200, Len Baker wrote:
> There is a regular need in the kernel to provide a way to declare having
> a dynamically sized set of trailing elements in a structure. Kernel code
> should always use "flexible array members"[1] for these cases. The older
> style of one-element or zero-length arrays should no longer be used[2].
>
> Also, refactor the code a bit to make use of the struct_size() helper in
> kzalloc().
>
> [1] https://en.wikipedia.org/wiki/Flexible_array_member
> [2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arrays
>
> Signed-off-by: Len Baker <len.baker@gmx.com>
> ---
> drivers/net/wireless/ath/ath11k/reg.c | 7 ++-----
> drivers/net/wireless/ath/ath11k/wmi.h | 2 +-
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath11k/reg.c b/drivers/net/wireless/ath/ath11k/reg.c
> index e1a1df169034..c83d265185f1 100644
> --- a/drivers/net/wireless/ath/ath11k/reg.c
> +++ b/drivers/net/wireless/ath/ath11k/reg.c
> @@ -97,7 +97,6 @@ int ath11k_reg_update_chan_list(struct ath11k *ar)
> struct channel_param *ch;
> enum nl80211_band band;
> int num_channels = 0;
> - int params_len;
> int i, ret;
>
> bands = hw->wiphy->bands;
> @@ -117,10 +116,8 @@ int ath11k_reg_update_chan_list(struct ath11k *ar)
> if (WARN_ON(!num_channels))
> return -EINVAL;
>
> - params_len = sizeof(struct scan_chan_list_params) +
> - num_channels * sizeof(struct channel_param);
> - params = kzalloc(params_len, GFP_KERNEL);
> -
> + params = kzalloc(struct_size(params, ch_param, num_channels),
> + GFP_KERNEL);
> if (!params)
> return -ENOMEM;
>
> diff --git a/drivers/net/wireless/ath/ath11k/wmi.h b/drivers/net/wireless/ath/ath11k/wmi.h
> index d35c47e0b19d..d9c83726f65d 100644
> --- a/drivers/net/wireless/ath/ath11k/wmi.h
> +++ b/drivers/net/wireless/ath/ath11k/wmi.h
> @@ -3608,7 +3608,7 @@ struct wmi_stop_scan_cmd {
> struct scan_chan_list_params {
> u32 pdev_id;
> u16 nallchans;
> - struct channel_param ch_param[1];
> + struct channel_param ch_param[];
> };
>
> struct wmi_scan_chan_list_cmd {
> --
> 2.25.1
>
next prev parent reply other threads:[~2021-09-12 19:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-04 11:49 [PATCH] ath11k: Replace one-element array with flexible-array member Len Baker
2021-09-12 19:31 ` Gustavo A. R. Silva [this message]
2021-09-12 19:42 ` Gustavo A. R. Silva
2021-09-14 5:53 ` Kalle Valo
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=20210912193140.GC146608@embeddedor \
--to=gustavoars@kernel.org \
--cc=ath11k@lists.infradead.org \
--cc=davem@davemloft.net \
--cc=gustavo@embeddedor.com \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=kvalo@codeaurora.org \
--cc=len.baker@gmx.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).