All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame
@ 2022-04-03 16:54 Martin Kaiser
  2022-04-03 16:54 ` [PATCH 01/11] staging: r8188eu: use ieee80211 helper for source address Martin Kaiser
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Use ieee80211 helpers, remove temporary variables, simplify the error
handling. Refactor the code for checking to_ds, from_ds.

Martin Kaiser (11):
  staging: r8188eu: use ieee80211 helper for source address
  staging: r8188eu: use ieee80211 helper for destination address
  staging: r8188eu: use ieee80211 helper for retry bit
  staging: r8188eu: simplify error handling
  staging: r8188eu: to_fr_ds cannot be 3 here
  staging: r8188eu: don't copy ra and ta before we fail
  staging: r8188eu: remove to_fr_ds from struct rx_pkt_attrib
  staging: r8188eu: ra and ta do not depend on to_ds, from_ds
  staging: r8188eu: remove psa, pda
  staging: r8188eu: don't call get_hdr_bssid
  staging: r8188eu: remove the bretry variable

 drivers/staging/r8188eu/core/rtw_recv.c    | 84 +++++++---------------
 drivers/staging/r8188eu/include/rtw_recv.h |  1 -
 drivers/staging/r8188eu/include/wifi.h     |  2 -
 3 files changed, 26 insertions(+), 61 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 01/11] staging: r8188eu: use ieee80211 helper for source address
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 02/11] staging: r8188eu: use ieee80211 helper for destination address Martin Kaiser
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Use the ieee80211_get_SA helper to get a pointer to the source
address of the incoming data frame.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 9f0bb29c9c56..597c6291f098 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -940,13 +940,14 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	u8 *psa, *pda, *pbssid;
 	struct sta_info *psta = NULL;
 	u8 *ptr = precv_frame->rx_data;
+	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
 	struct rx_pkt_attrib	*pattrib = &precv_frame->attrib;
 	struct security_priv	*psecuritypriv = &adapter->securitypriv;
 	int ret = _SUCCESS;
 
 	bretry = GetRetry(ptr);
 	pda = get_da(ptr);
-	psa = get_sa(ptr);
+	psa = ieee80211_get_SA(hdr);
 	pbssid = get_hdr_bssid(ptr);
 
 	if (!pbssid) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 02/11] staging: r8188eu: use ieee80211 helper for destination address
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
  2022-04-03 16:54 ` [PATCH 01/11] staging: r8188eu: use ieee80211 helper for source address Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 03/11] staging: r8188eu: use ieee80211 helper for retry bit Martin Kaiser
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Use the ieee80211_get_DA helper to get a pointer to the destination
address of the incoming data frame.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 597c6291f098..89b6e30915ce 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -946,7 +946,7 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	int ret = _SUCCESS;
 
 	bretry = GetRetry(ptr);
-	pda = get_da(ptr);
+	pda = ieee80211_get_DA(hdr);
 	psa = ieee80211_get_SA(hdr);
 	pbssid = get_hdr_bssid(ptr);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 03/11] staging: r8188eu: use ieee80211 helper for retry bit
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
  2022-04-03 16:54 ` [PATCH 01/11] staging: r8188eu: use ieee80211 helper for source address Martin Kaiser
  2022-04-03 16:54 ` [PATCH 02/11] staging: r8188eu: use ieee80211 helper for destination address Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 04/11] staging: r8188eu: simplify error handling Martin Kaiser
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Use the ieee80211 helper to check if the retry bit is set in the incoming
data frame.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 89b6e30915ce..c75b0592a63d 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -945,7 +945,7 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	struct security_priv	*psecuritypriv = &adapter->securitypriv;
 	int ret = _SUCCESS;
 
-	bretry = GetRetry(ptr);
+	bretry = ieee80211_has_retry(hdr->frame_control);
 	pda = ieee80211_get_DA(hdr);
 	psa = ieee80211_get_SA(hdr);
 	pbssid = get_hdr_bssid(ptr);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 04/11] staging: r8188eu: simplify error handling
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (2 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 03/11] staging: r8188eu: use ieee80211 helper for retry bit Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 05/11] staging: r8188eu: to_fr_ds cannot be 3 here Martin Kaiser
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Simplify the error handling in validate_recv_data_frame. The function does
not have to do any cleanup for errors, we can return immediately.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 33 +++++++++----------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index c75b0592a63d..200d8c6c6e11 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -943,17 +943,15 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
 	struct rx_pkt_attrib	*pattrib = &precv_frame->attrib;
 	struct security_priv	*psecuritypriv = &adapter->securitypriv;
-	int ret = _SUCCESS;
+	int ret;
 
 	bretry = ieee80211_has_retry(hdr->frame_control);
 	pda = ieee80211_get_DA(hdr);
 	psa = ieee80211_get_SA(hdr);
-	pbssid = get_hdr_bssid(ptr);
 
-	if (!pbssid) {
-		ret = _FAIL;
-		goto exit;
-	}
+	pbssid = get_hdr_bssid(ptr);
+	if (!pbssid)
+		return _FAIL;
 
 	memcpy(pattrib->dst, pda, ETH_ALEN);
 	memcpy(pattrib->src, psa, ETH_ALEN);
@@ -986,16 +984,11 @@ static int validate_recv_data_frame(struct adapter *adapter,
 		break;
 	}
 
-	if (ret == _FAIL) {
-		goto exit;
-	} else if (ret == RTW_RX_HANDLED) {
-		goto exit;
-	}
+	if (ret == _FAIL || ret == RTW_RX_HANDLED)
+		return ret;
 
-	if (!psta) {
-		ret = _FAIL;
-		goto exit;
-	}
+	if (!psta)
+		return _FAIL;
 
 	/* psta->rssi = prxcmd->rssi; */
 	/* psta->signal_quality = prxcmd->sq; */
@@ -1023,10 +1016,8 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
 
 	/*  decache, drop duplicate recv packets */
-	if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
-		ret = _FAIL;
-		goto exit;
-	}
+	if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL)
+		return _FAIL;
 
 	if (pattrib->privacy) {
 		GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, is_multicast_ether_addr(pattrib->ra));
@@ -1038,9 +1029,7 @@ static int validate_recv_data_frame(struct adapter *adapter,
 		pattrib->icv_len = 0;
 	}
 
-exit:
-
-	return ret;
+	return _SUCCESS;
 }
 
 static int validate_recv_frame(struct adapter *adapter, struct recv_frame *precv_frame)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 05/11] staging: r8188eu: to_fr_ds cannot be 3 here
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (3 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 04/11] staging: r8188eu: simplify error handling Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 06/11] staging: r8188eu: don't copy ra and ta before we fail Martin Kaiser
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Remove two unnecessary ternary operators in validate_recv_data_frame.
pattrib->to_fr_ds cannot be 3 in these places. If it was 3, we'd already
have returned an error to the caller.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 200d8c6c6e11..47d4fd01824f 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -1001,13 +1001,13 @@ static int validate_recv_data_frame(struct adapter *adapter,
 		pattrib->priority = GetPriority((ptr + 24));
 		pattrib->ack_policy = GetAckpolicy((ptr + 24));
 		pattrib->amsdu = GetAMsdu((ptr + 24));
-		pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
+		pattrib->hdrlen = 26;
 
 		if (pattrib->priority != 0 && pattrib->priority != 3)
 			adapter->recvpriv.bIsAnyNonBEPkts = true;
 	} else {
 		pattrib->priority = 0;
-		pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
+		pattrib->hdrlen = 24;
 	}
 
 	if (pattrib->order)/* HT-CTRL 11n */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 06/11] staging: r8188eu: don't copy ra and ta before we fail
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (4 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 05/11] staging: r8188eu: to_fr_ds cannot be 3 here Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 07/11] staging: r8188eu: remove to_fr_ds from struct rx_pkt_attrib Martin Kaiser
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

In validate_recv_data_frame, we return an error if both to_ds and
from_ds are set in the incoming data frame. There's no need to populate
patrib->ra and ta before we return. The caller will free the received
frame, including pattrib.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 47d4fd01824f..c200e1251545 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -974,11 +974,6 @@ static int validate_recv_data_frame(struct adapter *adapter,
 		memcpy(pattrib->ta, psa, ETH_ALEN);
 		ret = sta2ap_data_frame(adapter, precv_frame, &psta);
 		break;
-	case 3:
-		memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
-		memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
-		ret = _FAIL;
-		break;
 	default:
 		ret = _FAIL;
 		break;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 07/11] staging: r8188eu: remove to_fr_ds from struct rx_pkt_attrib
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (5 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 06/11] staging: r8188eu: don't copy ra and ta before we fail Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 08/11] staging: r8188eu: ra and ta do not depend on to_ds, from_ds Martin Kaiser
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

to_fr_ds in struct rx_pkt_attrib stores the values of the to_ds and
from_ds bits of an incoming data frame. to_fr_ds is set by parsing the
frame control bytes and it's used only in validate_recv_data_frame.

Remove to_fr_ds from struct rx_pkt_attrib and use the ieee80211 helpers
to distinguish between the four different cases for to_ds, from_ds.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c    | 26 +++++++++-------------
 drivers/staging/r8188eu/include/rtw_recv.h |  1 -
 drivers/staging/r8188eu/include/wifi.h     |  2 --
 3 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index c200e1251545..0098f3de31d7 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -958,25 +958,22 @@ static int validate_recv_data_frame(struct adapter *adapter,
 
 	memcpy(pattrib->bssid, pbssid, ETH_ALEN);
 
-	switch (pattrib->to_fr_ds) {
-	case 0:
-		memcpy(pattrib->ra, pda, ETH_ALEN);
-		memcpy(pattrib->ta, psa, ETH_ALEN);
-		ret = sta2sta_data_frame(adapter, precv_frame, &psta);
-		break;
-	case 1:
+	/* address4 is used only if both to_ds and from_ds are set */
+	if (ieee80211_has_a4(hdr->frame_control))
+		return _FAIL;
+
+	if (ieee80211_has_fromds(hdr->frame_control)) {
 		memcpy(pattrib->ra, pda, ETH_ALEN);
 		memcpy(pattrib->ta, pbssid, ETH_ALEN);
 		ret = ap2sta_data_frame(adapter, precv_frame, &psta);
-		break;
-	case 2:
+	} else if (ieee80211_has_tods(hdr->frame_control)) {
 		memcpy(pattrib->ra, pbssid, ETH_ALEN);
 		memcpy(pattrib->ta, psa, ETH_ALEN);
 		ret = sta2ap_data_frame(adapter, precv_frame, &psta);
-		break;
-	default:
-		ret = _FAIL;
-		break;
+	} else {
+		memcpy(pattrib->ra, pda, ETH_ALEN);
+		memcpy(pattrib->ta, psa, ETH_ALEN);
+		ret = sta2sta_data_frame(adapter, precv_frame, &psta);
 	}
 
 	if (ret == _FAIL || ret == RTW_RX_HANDLED)
@@ -1035,7 +1032,6 @@ static int validate_recv_frame(struct adapter *adapter, struct recv_frame *precv
 
 	int retval = _FAIL;
 	struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
-	u8 *ptr = precv_frame->rx_data;
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
 	struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
 
@@ -1048,8 +1044,6 @@ static int validate_recv_frame(struct adapter *adapter, struct recv_frame *precv
 	if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_VERS)) != 0)
 		return _FAIL;
 
-	pattrib->to_fr_ds = get_tofr_ds(ptr);
-
 	pattrib->frag_num = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
 	pattrib->seq_num = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
 
diff --git a/drivers/staging/r8188eu/include/rtw_recv.h b/drivers/staging/r8188eu/include/rtw_recv.h
index 4ac4e6b3e177..59b4773bc3c9 100644
--- a/drivers/staging/r8188eu/include/rtw_recv.h
+++ b/drivers/staging/r8188eu/include/rtw_recv.h
@@ -80,7 +80,6 @@ struct rx_pkt_attrib {
 	u8	drvinfo_sz;
 	u8	shift_sz;
 	u8	hdrlen; /* the WLAN Header Len */
-	u8	to_fr_ds;
 	u8	amsdu;
 	bool	qos;
 	u8	priority;
diff --git a/drivers/staging/r8188eu/include/wifi.h b/drivers/staging/r8188eu/include/wifi.h
index eb3cb1fb285f..a252a416d3e5 100644
--- a/drivers/staging/r8188eu/include/wifi.h
+++ b/drivers/staging/r8188eu/include/wifi.h
@@ -152,8 +152,6 @@ enum WIFI_REG_DOMAIN {
 
 #define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
 
-#define get_tofr_ds(pframe)	((GetToDs(pframe) << 1) | GetFrDs(pframe))
-
 #define SetMFrag(pbuf)	\
 	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_)
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 08/11] staging: r8188eu: ra and ta do not depend on to_ds, from_ds
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (6 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 07/11] staging: r8188eu: remove to_fr_ds from struct rx_pkt_attrib Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 09/11] staging: r8188eu: remove psa, pda Martin Kaiser
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

The "DS bit usage" table in include/linux/ieee80211.h shows that
ra is always addr1 and ta is always addr2.

We can set pattrib->ra and pattrib->ta regardless of the to_ds and
from_ds bits.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 0098f3de31d7..75c0e0b17185 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -962,19 +962,15 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	if (ieee80211_has_a4(hdr->frame_control))
 		return _FAIL;
 
-	if (ieee80211_has_fromds(hdr->frame_control)) {
-		memcpy(pattrib->ra, pda, ETH_ALEN);
-		memcpy(pattrib->ta, pbssid, ETH_ALEN);
+	memcpy(pattrib->ra, hdr->addr1, ETH_ALEN);
+	memcpy(pattrib->ta, hdr->addr2, ETH_ALEN);
+
+	if (ieee80211_has_fromds(hdr->frame_control))
 		ret = ap2sta_data_frame(adapter, precv_frame, &psta);
-	} else if (ieee80211_has_tods(hdr->frame_control)) {
-		memcpy(pattrib->ra, pbssid, ETH_ALEN);
-		memcpy(pattrib->ta, psa, ETH_ALEN);
+	else if (ieee80211_has_tods(hdr->frame_control))
 		ret = sta2ap_data_frame(adapter, precv_frame, &psta);
-	} else {
-		memcpy(pattrib->ra, pda, ETH_ALEN);
-		memcpy(pattrib->ta, psa, ETH_ALEN);
+	else
 		ret = sta2sta_data_frame(adapter, precv_frame, &psta);
-	}
 
 	if (ret == _FAIL || ret == RTW_RX_HANDLED)
 		return ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 09/11] staging: r8188eu: remove psa, pda
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (7 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 08/11] staging: r8188eu: ra and ta do not depend on to_ds, from_ds Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 10/11] staging: r8188eu: don't call get_hdr_bssid Martin Kaiser
  2022-04-03 16:54 ` [PATCH 11/11] staging: r8188eu: remove the bretry variable Martin Kaiser
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Remove the psa, pda variables. They are set and read only once.
We can use the ieee80211 helpers directly.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 75c0e0b17185..63ce66489146 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -937,7 +937,7 @@ static int validate_recv_data_frame(struct adapter *adapter,
 				    struct recv_frame *precv_frame)
 {
 	u8 bretry;
-	u8 *psa, *pda, *pbssid;
+	u8 *pbssid;
 	struct sta_info *psta = NULL;
 	u8 *ptr = precv_frame->rx_data;
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
@@ -946,15 +946,13 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	int ret;
 
 	bretry = ieee80211_has_retry(hdr->frame_control);
-	pda = ieee80211_get_DA(hdr);
-	psa = ieee80211_get_SA(hdr);
 
 	pbssid = get_hdr_bssid(ptr);
 	if (!pbssid)
 		return _FAIL;
 
-	memcpy(pattrib->dst, pda, ETH_ALEN);
-	memcpy(pattrib->src, psa, ETH_ALEN);
+	memcpy(pattrib->dst, ieee80211_get_DA(hdr), ETH_ALEN);
+	memcpy(pattrib->src, ieee80211_get_SA(hdr), ETH_ALEN);
 
 	memcpy(pattrib->bssid, pbssid, ETH_ALEN);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 10/11] staging: r8188eu: don't call get_hdr_bssid
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (8 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 09/11] staging: r8188eu: remove psa, pda Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  2022-04-03 16:54 ` [PATCH 11/11] staging: r8188eu: remove the bretry variable Martin Kaiser
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Do not call get_hdr_bssid from validate_recv_data_frame.

We already distinguish between the four cases for to_ds, from_ds. Copy
the bssid address as described in the "DS bit usage" table in
include/linux/ieee80211.h.

Eventually, we should remove get_hdr_bssid (and other similar
driver-specific parsing functions).

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index 63ce66489146..e9209785b1c9 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -937,7 +937,6 @@ static int validate_recv_data_frame(struct adapter *adapter,
 				    struct recv_frame *precv_frame)
 {
 	u8 bretry;
-	u8 *pbssid;
 	struct sta_info *psta = NULL;
 	u8 *ptr = precv_frame->rx_data;
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
@@ -947,15 +946,9 @@ static int validate_recv_data_frame(struct adapter *adapter,
 
 	bretry = ieee80211_has_retry(hdr->frame_control);
 
-	pbssid = get_hdr_bssid(ptr);
-	if (!pbssid)
-		return _FAIL;
-
 	memcpy(pattrib->dst, ieee80211_get_DA(hdr), ETH_ALEN);
 	memcpy(pattrib->src, ieee80211_get_SA(hdr), ETH_ALEN);
 
-	memcpy(pattrib->bssid, pbssid, ETH_ALEN);
-
 	/* address4 is used only if both to_ds and from_ds are set */
 	if (ieee80211_has_a4(hdr->frame_control))
 		return _FAIL;
@@ -963,12 +956,16 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	memcpy(pattrib->ra, hdr->addr1, ETH_ALEN);
 	memcpy(pattrib->ta, hdr->addr2, ETH_ALEN);
 
-	if (ieee80211_has_fromds(hdr->frame_control))
+	if (ieee80211_has_fromds(hdr->frame_control)) {
+		memcpy(pattrib->bssid, hdr->addr2, ETH_ALEN);
 		ret = ap2sta_data_frame(adapter, precv_frame, &psta);
-	else if (ieee80211_has_tods(hdr->frame_control))
+	} else if (ieee80211_has_tods(hdr->frame_control)) {
+		memcpy(pattrib->bssid, hdr->addr1, ETH_ALEN);
 		ret = sta2ap_data_frame(adapter, precv_frame, &psta);
-	else
+	} else {
+		memcpy(pattrib->bssid, hdr->addr3, ETH_ALEN);
 		ret = sta2sta_data_frame(adapter, precv_frame, &psta);
+	}
 
 	if (ret == _FAIL || ret == RTW_RX_HANDLED)
 		return ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 11/11] staging: r8188eu: remove the bretry variable
  2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
                   ` (9 preceding siblings ...)
  2022-04-03 16:54 ` [PATCH 10/11] staging: r8188eu: don't call get_hdr_bssid Martin Kaiser
@ 2022-04-03 16:54 ` Martin Kaiser
  10 siblings, 0 replies; 12+ messages in thread
From: Martin Kaiser @ 2022-04-03 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Remove the bretry variable. It's set and used only once. Call the
ieee80211 helper directly.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index e9209785b1c9..91a6e0f035f4 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -936,7 +936,6 @@ static void validate_recv_mgnt_frame(struct adapter *padapter,
 static int validate_recv_data_frame(struct adapter *adapter,
 				    struct recv_frame *precv_frame)
 {
-	u8 bretry;
 	struct sta_info *psta = NULL;
 	u8 *ptr = precv_frame->rx_data;
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)precv_frame->rx_data;
@@ -944,8 +943,6 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	struct security_priv	*psecuritypriv = &adapter->securitypriv;
 	int ret;
 
-	bretry = ieee80211_has_retry(hdr->frame_control);
-
 	memcpy(pattrib->dst, ieee80211_get_DA(hdr), ETH_ALEN);
 	memcpy(pattrib->src, ieee80211_get_SA(hdr), ETH_ALEN);
 
@@ -999,7 +996,8 @@ static int validate_recv_data_frame(struct adapter *adapter,
 	precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
 
 	/*  decache, drop duplicate recv packets */
-	if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL)
+	if (recv_decache(precv_frame, ieee80211_has_retry(hdr->frame_control),
+			 &psta->sta_recvpriv.rxcache) == _FAIL)
 		return _FAIL;
 
 	if (pattrib->privacy) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-04-03 16:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 16:54 [PATCH 00/11] staging: r8188eu: clean up validate_recv_data_frame Martin Kaiser
2022-04-03 16:54 ` [PATCH 01/11] staging: r8188eu: use ieee80211 helper for source address Martin Kaiser
2022-04-03 16:54 ` [PATCH 02/11] staging: r8188eu: use ieee80211 helper for destination address Martin Kaiser
2022-04-03 16:54 ` [PATCH 03/11] staging: r8188eu: use ieee80211 helper for retry bit Martin Kaiser
2022-04-03 16:54 ` [PATCH 04/11] staging: r8188eu: simplify error handling Martin Kaiser
2022-04-03 16:54 ` [PATCH 05/11] staging: r8188eu: to_fr_ds cannot be 3 here Martin Kaiser
2022-04-03 16:54 ` [PATCH 06/11] staging: r8188eu: don't copy ra and ta before we fail Martin Kaiser
2022-04-03 16:54 ` [PATCH 07/11] staging: r8188eu: remove to_fr_ds from struct rx_pkt_attrib Martin Kaiser
2022-04-03 16:54 ` [PATCH 08/11] staging: r8188eu: ra and ta do not depend on to_ds, from_ds Martin Kaiser
2022-04-03 16:54 ` [PATCH 09/11] staging: r8188eu: remove psa, pda Martin Kaiser
2022-04-03 16:54 ` [PATCH 10/11] staging: r8188eu: don't call get_hdr_bssid Martin Kaiser
2022-04-03 16:54 ` [PATCH 11/11] staging: r8188eu: remove the bretry variable Martin Kaiser

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.