From: Serhat Kumral <serhatkumral1@gmail.com>
To: linux-staging@lists.linux.dev
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
lgs201920130244@gmail.com, error27@gmail.com,
Serhat Kumral <serhatkumral1@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH v2] staging: rtl8723bs: simplify rtw_spt_band_alloc
Date: Mon, 22 Jun 2026 19:09:47 +0300 [thread overview]
Message-ID: <20260622160947.7970-1-serhatkumral1@gmail.com> (raw)
The function only supports NL80211_BAND_2GHZ and falls through to
exit for any other band. Replace the n_channels and n_bitrates local
variables with the compile-time constants RTW_2G_CHANNELS_NUM and
RTW_G_RATES_NUM directly.
Use simple addition in kzalloc() instead of chained size_add() calls,
since the sizes are derived from compile-time constants and cannot
overflow. Replace the intermediate alloc_sz variable accordingly.
Remove the redundant second band check before the init calls, as
the early exit at the top of the function guarantees that only the
2GHz case can reach that point.
No functional change intended.
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Serhat Kumral <serhatkumral1@gmail.com>
---
.../staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 31 +++++++------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 1484336d7..dfc44ebb7 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -110,33 +110,26 @@ 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 channels_sz, bitrate_size;
- if (band == NL80211_BAND_2GHZ) {
- n_channels = RTW_2G_CHANNELS_NUM;
- n_bitrates = RTW_G_RATES_NUM;
- } else {
+ if (band != NL80211_BAND_2GHZ)
goto exit;
- }
- 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, array_size(n_bitrates, sizeof(struct ieee80211_rate)));
- spt_band = kzalloc(alloc_sz, GFP_KERNEL);
+ 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);
if (!spt_band)
goto exit;
- spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band));
- spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels);
+ spt_band->channels = (void *)spt_band + sizeof(*spt_band);
+ spt_band->bitrates = (void *)spt_band + sizeof(*spt_band) + channels_sz;
spt_band->band = band;
- spt_band->n_channels = n_channels;
- spt_band->n_bitrates = n_bitrates;
+ spt_band->n_channels = RTW_2G_CHANNELS_NUM;
+ spt_band->n_bitrates = RTW_G_RATES_NUM;
- if (band == NL80211_BAND_2GHZ) {
- rtw_2g_channels_init(spt_band->channels);
- rtw_2g_rates_init(spt_band->bitrates);
- }
+ rtw_2g_channels_init(spt_band->channels);
+ rtw_2g_rates_init(spt_band->bitrates);
/* spt_band.ht_cap */
--
2.54.0
next reply other threads:[~2026-06-22 16:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 16:09 Serhat Kumral [this message]
2026-06-23 5:21 ` [PATCH v2] staging: rtl8723bs: simplify rtw_spt_band_alloc Dan Carpenter
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=20260622160947.7970-1-serhatkumral1@gmail.com \
--to=serhatkumral1@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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