* [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq
@ 2026-01-16 16:08 William Hansen-Baird
2026-01-16 16:08 ` [PATCH 2/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement William Hansen-Baird
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-16 16:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, William Hansen-Baird
Refactor security ies parsing in OnAssocReq function into separate
helper function rtw_parse_assoc_security_ies.
Local variables from OnAssocReq wpa_ie, wpa_ie_len and psecuritypriv moved into
helper function as they're only used within the function.
This change significantly shortens OnAssocReq, and makes the logic
easier to reason about.
Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 231 +++++++++---------
1 file changed, 119 insertions(+), 112 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index ac49bfbaa5bb..83342d48e730 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -929,20 +929,132 @@ unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_fram
}
+static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
+ struct rtw_ieee802_11_elems *elems,
+ struct sta_info *pstat)
+{
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ unsigned char *wpa_ie;
+ int wpa_ie_len;
+
+ pstat->dot8021xalg = 0;
+ pstat->wpa_psk = 0;
+ pstat->wpa_group_cipher = 0;
+ pstat->wpa2_group_cipher = 0;
+ pstat->wpa_pairwise_cipher = 0;
+ pstat->wpa2_pairwise_cipher = 0;
+ memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
+ if ((psecuritypriv->wpa_psk & BIT(1)) && elems->rsn_ie) {
+
+ int group_cipher = 0, pairwise_cipher = 0;
+
+ wpa_ie = elems->rsn_ie;
+ wpa_ie_len = elems->rsn_ie_len;
+
+ if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
+ pstat->dot8021xalg = 1;/* psk, todo:802.1x */
+ pstat->wpa_psk |= BIT(1);
+
+ pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
+ pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
+
+ if (!pstat->wpa2_group_cipher)
+ return WLAN_STATUS_INVALID_GROUP_CIPHER;
+
+ if (!pstat->wpa2_pairwise_cipher)
+ return WLAN_STATUS_INVALID_PAIRWISE_CIPHER;
+ } else {
+ return WLAN_STATUS_INVALID_IE;
+ }
+
+ } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems->wpa_ie) {
+
+ int group_cipher = 0, pairwise_cipher = 0;
+
+ wpa_ie = elems->wpa_ie;
+ wpa_ie_len = elems->wpa_ie_len;
+
+ if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
+ pstat->dot8021xalg = 1;/* psk, todo:802.1x */
+ pstat->wpa_psk |= BIT(0);
+
+ pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
+ pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
+
+ if (!pstat->wpa_group_cipher)
+ return WLAN_STATUS_INVALID_GROUP_CIPHER;
+
+ if (!pstat->wpa_pairwise_cipher)
+ return WLAN_STATUS_INVALID_PAIRWISE_CIPHER;
+
+ } else {
+ return WLAN_STATUS_INVALID_IE;
+ }
+
+ } else {
+ wpa_ie = NULL;
+ wpa_ie_len = 0;
+ }
+
+ pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
+ if (!wpa_ie) {
+ if (elems->wps_ie) {
+ pstat->flags |= WLAN_STA_WPS;
+ } else {
+ pstat->flags |= WLAN_STA_MAYBE_WPS;
+ }
+
+
+ /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
+ /* that the selected registrar of AP is _FLASE */
+ if ((psecuritypriv->wpa_psk > 0)
+ && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
+ if (pmlmepriv->wps_beacon_ie) {
+ u8 selected_registrar = 0;
+
+ rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
+
+ if (!selected_registrar)
+ return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
+ }
+ }
+
+ } else {
+ int copy_len;
+
+ if (psecuritypriv->wpa_psk == 0) {
+ return WLAN_STATUS_INVALID_IE;
+ }
+
+ if (elems->wps_ie) {
+ pstat->flags |= WLAN_STA_WPS;
+ copy_len = 0;
+ } else {
+ copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
+ }
+
+
+ if (copy_len > 0)
+ memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
+
+ }
+ return WLAN_STATUS_SUCCESS;
+}
+
unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
{
u16 capab_info;
struct rtw_ieee802_11_elems elems;
struct sta_info *pstat;
- unsigned char *p, *pos, *wpa_ie;
+ unsigned char *p, *pos;
unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
- int i, ie_len, wpa_ie_len, left;
+ int i, ie_len, left;
unsigned char supportRate[16];
int supportRateNum;
- unsigned short status = WLAN_STATUS_SUCCESS;
+ unsigned short status = WLAN_STATUS_SUCCESS, parse_status;
unsigned short frame_type, ie_offset = 0;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
- struct security_priv *psecuritypriv = &padapter->securitypriv;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
@@ -1056,118 +1168,13 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
update_basic_rate_table_soft_ap(pstat->bssrateset, pstat->bssratelen);
/* check RSN/WPA/WPS */
- pstat->dot8021xalg = 0;
- pstat->wpa_psk = 0;
- pstat->wpa_group_cipher = 0;
- pstat->wpa2_group_cipher = 0;
- pstat->wpa_pairwise_cipher = 0;
- pstat->wpa2_pairwise_cipher = 0;
- memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
- if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
-
- int group_cipher = 0, pairwise_cipher = 0;
-
- wpa_ie = elems.rsn_ie;
- wpa_ie_len = elems.rsn_ie_len;
-
- if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
- pstat->dot8021xalg = 1;/* psk, todo:802.1x */
- pstat->wpa_psk |= BIT(1);
-
- pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
- pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
-
- if (!pstat->wpa2_group_cipher)
- status = WLAN_STATUS_INVALID_GROUP_CIPHER;
-
- if (!pstat->wpa2_pairwise_cipher)
- status = WLAN_STATUS_INVALID_PAIRWISE_CIPHER;
- } else {
- status = WLAN_STATUS_INVALID_IE;
- }
-
- } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
-
- int group_cipher = 0, pairwise_cipher = 0;
-
- wpa_ie = elems.wpa_ie;
- wpa_ie_len = elems.wpa_ie_len;
-
- if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
- pstat->dot8021xalg = 1;/* psk, todo:802.1x */
- pstat->wpa_psk |= BIT(0);
-
- pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
- pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
-
- if (!pstat->wpa_group_cipher)
- status = WLAN_STATUS_INVALID_GROUP_CIPHER;
-
- if (!pstat->wpa_pairwise_cipher)
- status = WLAN_STATUS_INVALID_PAIRWISE_CIPHER;
-
- } else {
- status = WLAN_STATUS_INVALID_IE;
- }
-
- } else {
- wpa_ie = NULL;
- wpa_ie_len = 0;
- }
+ parse_status = rtw_parse_assoc_security_ies(padapter, &elems, pstat);
+ if (parse_status != WLAN_STATUS_SUCCESS)
+ status = parse_status;
if (status != WLAN_STATUS_SUCCESS)
goto OnAssocReqFail;
- pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
- if (!wpa_ie) {
- if (elems.wps_ie) {
- pstat->flags |= WLAN_STA_WPS;
- } else {
- pstat->flags |= WLAN_STA_MAYBE_WPS;
- }
-
-
- /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
- /* that the selected registrar of AP is _FLASE */
- if ((psecuritypriv->wpa_psk > 0)
- && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
- if (pmlmepriv->wps_beacon_ie) {
- u8 selected_registrar = 0;
-
- rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
-
- if (!selected_registrar) {
- status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
-
- goto OnAssocReqFail;
- }
- }
- }
-
- } else {
- int copy_len;
-
- if (psecuritypriv->wpa_psk == 0) {
- status = WLAN_STATUS_INVALID_IE;
-
- goto OnAssocReqFail;
-
- }
-
- if (elems.wps_ie) {
- pstat->flags |= WLAN_STA_WPS;
- copy_len = 0;
- } else {
- copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
- }
-
-
- if (copy_len > 0)
- memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
-
- }
-
-
/* check if there is WMM IE & support WWM-PS */
pstat->flags &= ~WLAN_STA_WME;
pstat->qos_option = 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
@ 2026-01-16 16:08 ` William Hansen-Baird
2026-01-16 16:08 ` [PATCH 3/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove braces for one-line if-statements William Hansen-Baird
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-16 16:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, William Hansen-Baird
Replace else-statement setting wpa_ie to NULL and wpa_ie_len to 0 by
initialising these variables beforehand.
Else-statement which sets wpa_ie and wpa_ie_len is
unnecessary if variables are initialised to these values from the start.
Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 83342d48e730..d0c88f6c4ba7 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -935,8 +935,8 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
{
struct security_priv *psecuritypriv = &padapter->securitypriv;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
- unsigned char *wpa_ie;
- int wpa_ie_len;
+ unsigned char *wpa_ie = NULL;
+ int wpa_ie_len = 0;
pstat->dot8021xalg = 0;
pstat->wpa_psk = 0;
@@ -991,10 +991,6 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
} else {
return WLAN_STATUS_INVALID_IE;
}
-
- } else {
- wpa_ie = NULL;
- wpa_ie_len = 0;
}
pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
--
2.52.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove braces for one-line if-statements.
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
2026-01-16 16:08 ` [PATCH 2/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement William Hansen-Baird
@ 2026-01-16 16:08 ` William Hansen-Baird
2026-01-16 16:08 ` [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t() William Hansen-Baird
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-16 16:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, William Hansen-Baird
Remove unecessary braces for if-statements that have only 1 line
in rtw_parse_security_ies function.
This change is purely stylistic, and makes the single-line if-statements
take up less space.
Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index d0c88f6c4ba7..8e41eb61448f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -995,12 +995,10 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
if (!wpa_ie) {
- if (elems->wps_ie) {
+ if (elems->wps_ie)
pstat->flags |= WLAN_STA_WPS;
- } else {
+ else
pstat->flags |= WLAN_STA_MAYBE_WPS;
- }
-
/* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
/* that the selected registrar of AP is _FLASE */
@@ -1019,9 +1017,8 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
} else {
int copy_len;
- if (psecuritypriv->wpa_psk == 0) {
+ if (psecuritypriv->wpa_psk == 0)
return WLAN_STATUS_INVALID_IE;
- }
if (elems->wps_ie) {
pstat->flags |= WLAN_STA_WPS;
@@ -1035,6 +1032,7 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
}
+
return WLAN_STATUS_SUCCESS;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t()
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
2026-01-16 16:08 ` [PATCH 2/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement William Hansen-Baird
2026-01-16 16:08 ` [PATCH 3/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove braces for one-line if-statements William Hansen-Baird
@ 2026-01-16 16:08 ` William Hansen-Baird
2026-01-27 14:37 ` Greg KH
2026-01-16 16:08 ` [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow William Hansen-Baird
2026-01-27 14:39 ` [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq Greg KH
4 siblings, 1 reply; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-16 16:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, William Hansen-Baird
Replace ternary comparison for setting copy_len with the min_t() function
from linux/minmax.h.
Change is purely cosmetic, however makes the line easier to read without having to reason
about logic.
Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 8e41eb61448f..842e95e1eaec 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -4,6 +4,7 @@
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
******************************************************************************/
+#include <linux/minmax.h>
#include <drv_types.h>
#include <rtw_wifi_regd.h>
#include <hal_btcoex.h>
@@ -1024,13 +1025,11 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
pstat->flags |= WLAN_STA_WPS;
copy_len = 0;
} else {
- copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
+ copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len+2);
}
-
if (copy_len > 0)
memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
-
}
return WLAN_STATUS_SUCCESS;
--
2.52.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
` (2 preceding siblings ...)
2026-01-16 16:08 ` [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t() William Hansen-Baird
@ 2026-01-16 16:08 ` William Hansen-Baird
2026-01-27 14:38 ` Greg KH
2026-01-27 14:39 ` [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq Greg KH
4 siblings, 1 reply; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-16 16:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, William Hansen-Baird
Initialize copy_len to 0 in rtw_parse_assoc_security_ies function.
This allows later if-statement to not have to explicitly set copy_len to 0.
Thus we can make the if statement single-lined, and remove the braces
from the if-else branch.
The change is purely cosmetic and changes no logic.
Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 842e95e1eaec..d470725a033f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -946,6 +946,7 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
pstat->wpa_pairwise_cipher = 0;
pstat->wpa2_pairwise_cipher = 0;
memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
+
if ((psecuritypriv->wpa_psk & BIT(1)) && elems->rsn_ie) {
int group_cipher = 0, pairwise_cipher = 0;
@@ -1016,17 +1017,15 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
}
} else {
- int copy_len;
+ int copy_len = 0;
if (psecuritypriv->wpa_psk == 0)
return WLAN_STATUS_INVALID_IE;
- if (elems->wps_ie) {
+ if (elems->wps_ie)
pstat->flags |= WLAN_STA_WPS;
- copy_len = 0;
- } else {
+ else
copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len+2);
- }
if (copy_len > 0)
memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
--
2.52.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t()
2026-01-16 16:08 ` [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t() William Hansen-Baird
@ 2026-01-27 14:37 ` Greg KH
0 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2026-01-27 14:37 UTC (permalink / raw)
To: William Hansen-Baird; +Cc: linux-staging, linux-kernel
On Fri, Jan 16, 2026 at 11:08:50AM -0500, William Hansen-Baird wrote:
> Replace ternary comparison for setting copy_len with the min_t() function
> from linux/minmax.h.
> Change is purely cosmetic, however makes the line easier to read without having to reason
> about logic.
>
> Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
> ---
> drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> index 8e41eb61448f..842e95e1eaec 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> @@ -4,6 +4,7 @@
> * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
> *
> ******************************************************************************/
> +#include <linux/minmax.h>
> #include <drv_types.h>
> #include <rtw_wifi_regd.h>
> #include <hal_btcoex.h>
> @@ -1024,13 +1025,11 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
> pstat->flags |= WLAN_STA_WPS;
> copy_len = 0;
> } else {
> - copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
> + copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len+2);
Why is the type needed here?
And your new line has a coding style problem, always run your patches
through checkpatch.pl please.
> }
>
> -
> if (copy_len > 0)
> memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
> -
These lines are not mentioned in the changelog :(
Remember, only do 1 thing per patch.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.
2026-01-16 16:08 ` [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow William Hansen-Baird
@ 2026-01-27 14:38 ` Greg KH
2026-01-31 22:10 ` William Hansen-Baird
0 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2026-01-27 14:38 UTC (permalink / raw)
To: William Hansen-Baird; +Cc: linux-staging, linux-kernel
On Fri, Jan 16, 2026 at 11:08:51AM -0500, William Hansen-Baird wrote:
> Initialize copy_len to 0 in rtw_parse_assoc_security_ies function.
> This allows later if-statement to not have to explicitly set copy_len to 0.
> Thus we can make the if statement single-lined, and remove the braces
> from the if-else branch.
> The change is purely cosmetic and changes no logic.
>
> Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
> ---
> drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> index 842e95e1eaec..d470725a033f 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> @@ -946,6 +946,7 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
> pstat->wpa_pairwise_cipher = 0;
> pstat->wpa2_pairwise_cipher = 0;
> memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
> +
> if ((psecuritypriv->wpa_psk & BIT(1)) && elems->rsn_ie) {
>
> int group_cipher = 0, pairwise_cipher = 0;
Why this line added?
> @@ -1016,17 +1017,15 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
> }
>
> } else {
> - int copy_len;
> + int copy_len = 0;
>
> if (psecuritypriv->wpa_psk == 0)
> return WLAN_STATUS_INVALID_IE;
>
> - if (elems->wps_ie) {
> + if (elems->wps_ie)
> pstat->flags |= WLAN_STA_WPS;
> - copy_len = 0;
> - } else {
> + else
> copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len+2);
> - }
>
> if (copy_len > 0)
> memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
I feel like this is just polishing the code for no reason at all. Why
make this change at all? What asked for it?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
` (3 preceding siblings ...)
2026-01-16 16:08 ` [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow William Hansen-Baird
@ 2026-01-27 14:39 ` Greg KH
2026-01-31 21:58 ` William Hansen-Baird
4 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2026-01-27 14:39 UTC (permalink / raw)
To: William Hansen-Baird; +Cc: linux-staging, linux-kernel
On Fri, Jan 16, 2026 at 11:08:47AM -0500, William Hansen-Baird wrote:
> + parse_status = rtw_parse_assoc_security_ies(padapter, &elems, pstat);
> + if (parse_status != WLAN_STATUS_SUCCESS)
> + status = parse_status;
>
> if (status != WLAN_STATUS_SUCCESS)
> goto OnAssocReqFail;
This logic makes no sense. Did you do this by hand or have a tool do it
for you?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq
2026-01-27 14:39 ` [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq Greg KH
@ 2026-01-31 21:58 ` William Hansen-Baird
0 siblings, 0 replies; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-31 21:58 UTC (permalink / raw)
To: Greg KH; +Cc: linux-staging, linux-kernel
On Tue, Jan 27, 2026 at 03:39:44PM +0100, Greg KH wrote:
> On Fri, Jan 16, 2026 at 11:08:47AM -0500, William Hansen-Baird wrote:
> > + parse_status = rtw_parse_assoc_security_ies(padapter, &elems, pstat);
> > + if (parse_status != WLAN_STATUS_SUCCESS)
> > + status = parse_status;
> >
> > if (status != WLAN_STATUS_SUCCESS)
> > goto OnAssocReqFail;
>
> This logic makes no sense. Did you do this by hand or have a tool do it
> for you?
>
I did it by hand. The original code checked the status after parsing
security IEs, only overwriting 'status' on parsing errors.
To preserve the original logic, I only overwrite 'status' if the parsing
of the security IEs was not successful.
Thanks,
William
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.
2026-01-27 14:38 ` Greg KH
@ 2026-01-31 22:10 ` William Hansen-Baird
0 siblings, 0 replies; 10+ messages in thread
From: William Hansen-Baird @ 2026-01-31 22:10 UTC (permalink / raw)
To: Greg KH; +Cc: linux-staging, linux-kernel
On Tue, Jan 27, 2026 at 03:38:29PM +0100, Greg KH wrote:
> On Fri, Jan 16, 2026 at 11:08:51AM -0500, William Hansen-Baird wrote:
> > Initialize copy_len to 0 in rtw_parse_assoc_security_ies function.
> > This allows later if-statement to not have to explicitly set copy_len to 0.
> > Thus we can make the if statement single-lined, and remove the braces
> > from the if-else branch.
> > The change is purely cosmetic and changes no logic.
> >
> > Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
> > ---
> > drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> > index 842e95e1eaec..d470725a033f 100644
> > --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> > +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> > @@ -946,6 +946,7 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
> > pstat->wpa_pairwise_cipher = 0;
> > pstat->wpa2_pairwise_cipher = 0;
> > memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
> > +
> > if ((psecuritypriv->wpa_psk & BIT(1)) && elems->rsn_ie) {
> >
> > int group_cipher = 0, pairwise_cipher = 0;
>
> Why this line added?
>
> > @@ -1016,17 +1017,15 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter,
> > }
> >
> > } else {
> > - int copy_len;
> > + int copy_len = 0;
> >
> > if (psecuritypriv->wpa_psk == 0)
> > return WLAN_STATUS_INVALID_IE;
> >
> > - if (elems->wps_ie) {
> > + if (elems->wps_ie)
> > pstat->flags |= WLAN_STA_WPS;
> > - copy_len = 0;
> > - } else {
> > + else
> > copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len+2);
> > - }
> >
> > if (copy_len > 0)
> > memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
>
> I feel like this is just polishing the code for no reason at all. Why
> make this change at all? What asked for it?
>
The change was really only polishing. There wasn't an issue to solve and
it was mainly a stylistic choice on my part.
If you prefer, I can drop this patch and keep the original style.
Thanks,
William
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-01-31 22:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-16 16:08 [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq William Hansen-Baird
2026-01-16 16:08 ` [PATCH 2/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement William Hansen-Baird
2026-01-16 16:08 ` [PATCH 3/5] staging: rtl8723bs: core/rtw_mlme_ext.c: remove braces for one-line if-statements William Hansen-Baird
2026-01-16 16:08 ` [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t() William Hansen-Baird
2026-01-27 14:37 ` Greg KH
2026-01-16 16:08 ` [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow William Hansen-Baird
2026-01-27 14:38 ` Greg KH
2026-01-31 22:10 ` William Hansen-Baird
2026-01-27 14:39 ` [PATCH 1/5] staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq Greg KH
2026-01-31 21:58 ` William Hansen-Baird
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox