lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260129080110.73884-1-tehsiu.huang@gmail.com>
Date: Thu, 29 Jan 2026 00:01:10 -0800
From: Michael Huang <tehsiu.huang@...il.com>
To: Dan Carpenter <dan.carpenter@...aro.org>,
	Joe Perches <joe@...ches.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-staging@...ts.linux.dev,
	linux-kernel@...r.kernel.org,
	Michael Huang <tehsiu.huang@...il.com>
Subject: [PATCH v2] 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>
---

v2:
  - Use kernel-style = {} for array initialization per Dan Carpenter.
  - Separate flags from data using bool arrays per Joe Perches.
  - Fix magic numbers with proper defines.
  - Retained the 2D structure for 'ch_present' despite only using class 0
    for now. This aligns with the IEEE 802.11 Regulatory Class/Channel 
    List hierarchy, making the code easier to map to the specification 
    and extensible for future operating class support.

v1:
  - Initial refactoring of the ICS array logic.

 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..dc2677275e0f 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] = {};
+	bool class_active[BSS_COEX_MAX_CLASSES] = {};
+	bool ch_present[BSS_COEX_MAX_CLASSES][BSS_COEX_MAX_CHANNELS] = {};
 
 	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

Powered by Openwall GNU/*/Linux Powered by OpenVZ