From: Dan Carpenter <error27@gmail.com>
To: Serhat Kumral <serhatkumral1@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8723bs: avoid duplicate size computation in rtw_spt_band_alloc
Date: Mon, 22 Jun 2026 12:20:34 +0300 [thread overview]
Message-ID: <ajj-YnZtw9mYALcv@stanley.mountain> (raw)
In-Reply-To: <20260621133301.13855-1-serhatkumral1@gmail.com>
On Sun, Jun 21, 2026 at 04:33:01PM +0300, Serhat Kumral wrote:
> Introduce a local variable to store the channel array size and reuse it
> for both the allocation and the bitrates pointer offset, replacing a
> redundant open-coded multiplication with the same array_size() result.
>
> Resolves the Coccinelle warning:
> WARNING: array_size is already used (line 124) to compute the same size
>
> Signed-off-by: Serhat Kumral <serhatkumral1@gmail.com>
> ---
> drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> index 1484336d7..2e65788ee 100644
> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> @@ -111,7 +111,7 @@ static struct ieee80211_supported_band *rtw_spt_band_alloc(
> {
> struct ieee80211_supported_band *spt_band = NULL;
> int n_channels, n_bitrates;
> - size_t alloc_sz;
> + size_t alloc_sz, channels_sz;
>
> if (band == NL80211_BAND_2GHZ) {
> n_channels = RTW_2G_CHANNELS_NUM;
> @@ -120,15 +120,16 @@ static struct ieee80211_supported_band *rtw_spt_band_alloc(
> goto exit;
> }
>
> + channels_sz = array_size(n_channels, sizeof(struct ieee80211_channel));
> alloc_sz = sizeof(*spt_band);
> - alloc_sz = size_add(alloc_sz, array_size(n_channels, sizeof(struct ieee80211_channel)));
> + alloc_sz = size_add(alloc_sz, channels_sz);
> alloc_sz = size_add(alloc_sz, array_size(n_bitrates, sizeof(struct ieee80211_rate)));
> spt_band = kzalloc(alloc_sz, GFP_KERNEL);
This is still a mess. First of all these size values are constant so
the layers of indirection are unnecessary. Pretending they are variable
makes code auditors have to check for integer overflows so it wastes
valuable time and makes the whole kernel less secure.
channels_sz = array_size(RTW_2G_CHANNELS_NUM, sizeof(struct ieee80211_channel));
bitrate_size = array_size(RTW_G_RATES_NUM, sizeof(struct ieee80211_rate));
spt_band = kzalloc(sizeof(*spt_band) + channels_sz + bitrate_size, GFP_KERNEL);
spt_band->channels = (void *)spt_band + sizeof(*spt_band);
spt_band->bitrates = (void *)spt_band + sizeof(*spt_band) + channels_sz;
regards,
dan carpenter
prev parent reply other threads:[~2026-06-22 9:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-21 13:33 [PATCH] staging: rtl8723bs: avoid duplicate size computation in rtw_spt_band_alloc Serhat Kumral
2026-06-22 9:20 ` Dan Carpenter [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=ajj-YnZtw9mYALcv@stanley.mountain \
--to=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=serhatkumral1@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