[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260128204510.53433-1-tehsiu.huang@gmail.com>
Date: Wed, 28 Jan 2026 12:45:10 -0800
From: Michael Huang <tehsiu.huang@...il.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Joe Perches <joe@...ches.com>,
linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Michael Huang <tehsiu.huang@...il.com>
Subject: [PATCH] staging: rtl8723bs: refactor BSS Coexistence channel report logic
Refactor the 'ICS' array in issue_action_BSSCoexistPacket() to improve
readability and maintainability. This addresses technical debt related
to magic numbers and ambiguous array usage.
The original implementation used a multi-purpose 2D array (ICS[8][15])
where magic numbers were prevalent and the first element of each row
was overloaded as a status flag. This patch:
- Introduces descriptive macros: BSS_COEX_MAX_CLASSES,
BSS_COEX_MAX_CHANNELS, and BSS_COEX_MAX_INFO_LEN.
- Splits the overloaded array into two distinct boolean arrays:
'class_active' (for group status) and 'ch_present' (for channel data).
- Converts the logic to use 'bool' types and 0-indexed loops,
conforming to standard C programming practices.
- Adds defensive boundary checks (ch > 0 && ch < MAX) to ensure
robustness against unexpected channel data.
This refactoring maintains the current 2.4GHz reporting behavior while
providing a structured and extensible foundation for future Operating
Class support according to IEEE 802.11 specifications.
Signed-off-by: Michael Huang <tehsiu.huang@...il.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 41 +++++++------------
.../staging/rtl8723bs/include/rtw_mlme_ext.h | 3 ++
2 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 884fcce50d9c..481295224f14 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -3587,8 +3587,9 @@ static void issue_action_BSSCoexistPacket(struct adapter *padapter)
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
struct __queue *queue = &(pmlmepriv->scanned_queue);
- u8 InfoContent[16] = {0};
- u8 ICS[8][15];
+ u8 InfoContent[BSS_COEX_MAX_INFO_LEN] = {0};
+ bool class_active[BSS_COEX_MAX_CLASSES] = {false};
+ bool ch_present[BSS_COEX_MAX_CLASSES][BSS_COEX_MAX_CHANNELS] = {{false}};
if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
return;
@@ -3642,7 +3643,6 @@ static void issue_action_BSSCoexistPacket(struct adapter *padapter)
/* */
- memset(ICS, 0, sizeof(ICS));
if (pmlmepriv->num_sta_no_ht > 0) {
int i;
@@ -3667,46 +3667,35 @@ static void issue_action_BSSCoexistPacket(struct adapter *padapter)
p = rtw_get_ie(pbss_network->ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, pbss_network->ie_length - _FIXED_IE_LENGTH_);
if (!p || len == 0) {/* non-HT */
+ u8 ch = pbss_network->configuration.ds_config;
- if (pbss_network->configuration.ds_config <= 0)
- continue;
-
- ICS[0][pbss_network->configuration.ds_config] = 1;
-
- if (ICS[0][0] == 0)
- ICS[0][0] = 1;
+ if (ch > 0 && ch < BSS_COEX_MAX_CHANNELS) {
+ ch_present[0][ch] = true;
+ class_active[0] = true;
+ }
}
}
spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
-
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < BSS_COEX_MAX_CLASSES; i++) {
int j, k = 0;
- if (ICS[i][0] != 1)
+ if (!class_active[i])
continue;
- InfoContent[k] = i;
+ InfoContent[k++] = i;
/* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */
- k++;
- for (j = 1; j <= 14; j++) {
- if (ICS[i][j] != 1)
- continue;
-
- if (k < 16) {
- InfoContent[k] = j; /* channel number */
- /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
- k++;
+ for (j = 0; j < BSS_COEX_MAX_CHANNELS; j++) {
+ if (ch_present[i][j]) {
+ if (k < BSS_COEX_MAX_INFO_LEN)
+ InfoContent[k++] = j; /* channel number */
}
}
-
pframe = rtw_set_ie(pframe, WLAN_EID_BSS_INTOLERANT_CHL_REPORT, k, InfoContent, &(pattrib->pktlen));
-
}
-
}
diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
index dd5080056e58..3a1067d6f164 100644
--- a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
@@ -41,6 +41,9 @@
#define _HW_STATE_STATION_ 0x02
#define _HW_STATE_AP_ 0x03
+#define BSS_COEX_MAX_CLASSES 8
+#define BSS_COEX_MAX_CHANNELS 15
+#define BSS_COEX_MAX_INFO_LEN 16
#define _1M_RATE_ 0
#define _2M_RATE_ 1
--
2.43.0
Powered by blists - more mailing lists