Skip to contentSkip to conversation

staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq

PATCH In review William Hansen-Baird 2 participants 10 messages Jan 16 – Jan 31 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 staging: rtl8723bs: core/rtw_mlme_ext.c: refactor security IE parsing in OnAssocReq

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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 231 +++++++++---------
 1 file changed, 119 insertions(+), 112 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +119 -112
index ac49bfbaa5bb..83342d48e730 100644
@@ -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;
Signature · 1 line
2.52.0
#1 lore raw

PATCH 2/5 staging: rtl8723bs: core/rtw_mlme_ext.c: remove unnecessary else statement

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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2 -6
index 83342d48e730..d0c88f6c4ba7 100644
@@ -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);
Signature · 1 line
2.52.0
#2 lore raw

PATCH 3/5 staging: rtl8723bs: core/rtw_mlme_ext.c: remove braces for one-line if-statements.

In reply to 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4 -6
index d0c88f6c4ba7..8e41eb61448f 100644
@@ -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;
 }
 
Signature · 1 line
2.52.0
#3 lore raw

PATCH 4/5 staging: rtl8723bs: replace ternary comparison with min_t()

In reply to 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2 -3
index 8e41eb61448f..842e95e1eaec 100644
@@ -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;
Signature · 1 line
2.52.0
maintainer
#4 lore raw

Re: [PATCH 4/5] staging: rtl8723bs: replace ternary comparison with min_t()

Quoted 23 lines · 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -0
index 8e41eb61448f..842e95e1eaec 100644
@@ -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>

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 1028

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -1
@@ -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.

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 1033

Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -2
 		}
 
-
 		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

#5 lore raw

PATCH 5/5 staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.

In reply to 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4 -5
index 842e95e1eaec..d470725a033f 100644
@@ -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);
Signature · 1 line
2.52.0
maintainer
#6 lore raw

Re: [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.

Quoted 16 lines · 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -0
index 842e95e1eaec..d470725a033f 100644

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 952

Quoted 7 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -0
@@ -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?

Quoted 11 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -2
@@ -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) {

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 1031

Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2 -3
+		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

#7 lore raw

Re: [PATCH 5/5] staging: rtl8723bs: core/rtw_mlme_ext.c: initialize copy_len, clearing later control-flow.

Quoted 46 lines · Greg KH
Quoted 16 lines · 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.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -0
index 842e95e1eaec..d470725a033f 100644

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 952

Quoted 7 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -0
@@ -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?

Quoted 19 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3 -5
@@ -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);
-		}
 
Quoted 6 lines

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, · line 1031

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -0
 		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

maintainer
#8 lore raw
In reply to William Hansen-Baird

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1176

Quoted 6 lines · William Hansen-Baird
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3 -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;

This logic makes no sense. Did you do this by hand or have a tool do it for you?

thanks,

greg k-h

#9 lore raw
Quoted 11 lines · Greg KH

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1176

Quoted 6 lines · William Hansen-Baird
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3 -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;

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