All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] staging: ks7010: Factor out repeated code.
@ 2018-03-16  6:26 Quytelda Kahja
  2018-03-19 18:51 ` Greg KH
  0 siblings, 1 reply; 25+ messages in thread
From: Quytelda Kahja @ 2018-03-16  6:26 UTC (permalink / raw)
  To: gregkh, wsa; +Cc: devel, driverdev-devel, linux-kernel, Quytelda Kahja

Some of the code for reading IEs is replicated multiple times in the
switch statement for get_ap_information().  Factor that code out into
read_ie().

Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
---
 drivers/staging/ks7010/ks_hostif.c | 48 +++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index 05f7be4638fe..a946ce76f899 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -223,6 +223,21 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
 	return 0;
 }
 
+static u8 read_ie(unsigned char *bp, u8 max, u8 *body, char *name)
+{
+	u8 size;
+
+	if (*(bp + 1) <= max) {
+		size = *(bp + 1);
+	} else {
+		DPRINTK(1, "size over :: %s size=%d\n", name, *(bp + 1));
+		size = max;
+	}
+
+	memcpy(body, bp + 2, size);
+	return size;
+}
+
 static
 int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 		       struct local_ap_t *ap)
@@ -253,14 +268,8 @@ int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 	while (bsize > offset) {
 		switch (*bp) { /* Information Element ID */
 		case WLAN_EID_SSID:
-			if (*(bp + 1) <= IEEE80211_MAX_SSID_LEN) {
-				ap->ssid.size = *(bp + 1);
-			} else {
-				DPRINTK(1, "size over :: ssid size=%d\n",
-					*(bp + 1));
-				ap->ssid.size = IEEE80211_MAX_SSID_LEN;
-			}
-			memcpy(ap->ssid.body, bp + 2, ap->ssid.size);
+			ap->ssid.size = read_ie(bp, IEEE80211_MAX_SSID_LEN,
+						ap->ssid.body, "ssid");
 			break;
 		case WLAN_EID_SUPP_RATES:
 		case WLAN_EID_EXT_SUPP_RATES:
@@ -283,28 +292,15 @@ int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 			break;
 		case WLAN_EID_RSN:
 			ap->rsn_ie.id = *bp;
-			if (*(bp + 1) <= RSN_IE_BODY_MAX) {
-				ap->rsn_ie.size = *(bp + 1);
-			} else {
-				DPRINTK(1, "size over :: rsn size=%d\n",
-					*(bp + 1));
-				ap->rsn_ie.size = RSN_IE_BODY_MAX;
-			}
-			memcpy(ap->rsn_ie.body, bp + 2, ap->rsn_ie.size);
+			ap->rsn_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
+						  ap->rsn_ie.body, "rsn");
 			break;
 		case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
 			if (memcmp(bp + 2, CIPHER_ID_WPA_WEP40, 4) == 0) { /* WPA OUI check */
 				ap->wpa_ie.id = *bp;
-				if (*(bp + 1) <= RSN_IE_BODY_MAX) {
-					ap->wpa_ie.size = *(bp + 1);
-				} else {
-					DPRINTK(1,
-						"size over :: wpa size=%d\n",
-						*(bp + 1));
-					ap->wpa_ie.size = RSN_IE_BODY_MAX;
-				}
-				memcpy(ap->wpa_ie.body, bp + 2,
-				       ap->wpa_ie.size);
+				ap->wpa_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
+							  ap->wpa_ie.body,
+							  "wpa");
 			}
 			break;
 
-- 
2.16.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 25+ messages in thread
* [PATCH 2/6] staging: ks7010: Factor out code into helper methods.
@ 2018-03-16  6:30 Quytelda Kahja
  0 siblings, 0 replies; 25+ messages in thread
From: Quytelda Kahja @ 2018-03-16  6:30 UTC (permalink / raw)
  To: gregkh, wsa; +Cc: devel, driverdev-devel, linux-kernel, Quytelda Kahja

Some cases in the switch statement in get_ap_information() are indented
as much as five levels, which makes the code difficult to read because
of all the wrapping.  Factor them out into helper methods.

Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
---
 drivers/staging/ks7010/ks_hostif.c | 46 +++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index a946ce76f899..948d45280d18 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -238,6 +238,30 @@ static u8 read_ie(unsigned char *bp, u8 max, u8 *body, char *name)
 	return size;
 }
 
+static void read_ie_ext_supp_rates(struct local_ap_t *ap, unsigned char *bp)
+{
+	if ((*(bp + 1) + ap->rate_set.size) <= RATE_SET_MAX_SIZE) {
+		memcpy(&ap->rate_set.body[ap->rate_set.size],
+		       bp + 2, *(bp + 1));
+		ap->rate_set.size += *(bp + 1);
+	} else {
+		DPRINTK(1, "size over :: rate size=%d\n",
+			(*(bp + 1) + ap->rate_set.size));
+		memcpy(&ap->rate_set.body[ap->rate_set.size], bp + 2,
+		       RATE_SET_MAX_SIZE - ap->rate_set.size);
+		ap->rate_set.size += (RATE_SET_MAX_SIZE - ap->rate_set.size);
+	}
+}
+
+static void read_ie_wpa(struct local_ap_t *ap, unsigned char *bp)
+{
+	if (memcmp(bp + 2, CIPHER_ID_WPA_WEP40, 4) == 0) { /* WPA OUI check */
+		ap->wpa_ie.id = *bp;
+		ap->wpa_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
+					  ap->wpa_ie.body, "wpa");
+	}
+}
+
 static
 int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 		       struct local_ap_t *ap)
@@ -273,20 +297,7 @@ int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 			break;
 		case WLAN_EID_SUPP_RATES:
 		case WLAN_EID_EXT_SUPP_RATES:
-			if ((*(bp + 1) + ap->rate_set.size) <=
-			    RATE_SET_MAX_SIZE) {
-				memcpy(&ap->rate_set.body[ap->rate_set.size],
-				       bp + 2, *(bp + 1));
-				ap->rate_set.size += *(bp + 1);
-			} else {
-				DPRINTK(1, "size over :: rate size=%d\n",
-					(*(bp + 1) + ap->rate_set.size));
-				memcpy(&ap->rate_set.body[ap->rate_set.size],
-				       bp + 2,
-				       RATE_SET_MAX_SIZE - ap->rate_set.size);
-				ap->rate_set.size +=
-				    (RATE_SET_MAX_SIZE - ap->rate_set.size);
-			}
+			read_ie_ext_supp_rates(ap, bp);
 			break;
 		case WLAN_EID_DS_PARAMS:
 			break;
@@ -296,12 +307,7 @@ int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
 						  ap->rsn_ie.body, "rsn");
 			break;
 		case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
-			if (memcmp(bp + 2, CIPHER_ID_WPA_WEP40, 4) == 0) { /* WPA OUI check */
-				ap->wpa_ie.id = *bp;
-				ap->wpa_ie.size = read_ie(bp, RSN_IE_BODY_MAX,
-							  ap->wpa_ie.body,
-							  "wpa");
-			}
+			read_ie_wpa(ap, bp);
 			break;
 
 		case WLAN_EID_FH_PARAMS:
-- 
2.16.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2018-03-28 11:50 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16  6:26 [PATCH 1/6] staging: ks7010: Factor out repeated code Quytelda Kahja
2018-03-19 18:51 ` Greg KH
2018-03-20  5:58   ` Quytelda Kahja
2018-03-20  5:58     ` [PATCH 2/6] staging: ks7010: Factor out code into helper methods Quytelda Kahja
2018-03-20  5:58     ` [PATCH 3/6] staging: ks7010: Remove unnecessary parentheses Quytelda Kahja
2018-03-22 17:19       ` Greg KH
2018-03-20  5:58     ` [PATCH 4/6] staging: ks7010: Remove unnecessary braces Quytelda Kahja
2018-03-20  5:58     ` [PATCH 5/6] staging: ks7010: Fix line over 80 characters Quytelda Kahja
2018-03-20  6:08       ` Joe Perches
2018-03-20  5:58     ` [PATCH 6/6] staging: ks7010: Factor out repeated request initialization code Quytelda Kahja
2018-03-22 17:19       ` Greg KH
2018-03-22 17:20     ` [PATCH 1/6] staging: ks7010: Factor out repeated code Greg KH
2018-03-23  5:07       ` [PATCH 1/7] staging: ks7010: Fix line over 80 characters Quytelda Kahja
2018-03-23  5:07         ` [PATCH 2/7] staging: ks7010: Fix lines over 80 characters due to comments Quytelda Kahja
2018-03-23  5:07         ` [PATCH 3/7] staging: ks7010: Factor out common members in request structs Quytelda Kahja
2018-03-23 14:58           ` Greg KH
2018-03-23 14:58             ` Greg KH
2018-03-24  6:40             ` [PATCH 1/2] staging: ks7010: Remove trailing "_t" from all structure names Quytelda Kahja
2018-03-24  6:40               ` [PATCH 2/2] staging: ks7010: Fix spelling mistakes Quytelda Kahja
2018-03-28 11:50               ` [PATCH 1/2] staging: ks7010: Remove trailing "_t" from all structure names Greg KH
2018-03-23  5:07         ` [PATCH 4/7] staging: ks7010: Remove duplicate #define's Quytelda Kahja
2018-03-23  5:07         ` [PATCH 5/7] staging: ks7010: Replace memcmp() operation with ether_addr_equal() Quytelda Kahja
2018-03-23  5:07         ` [PATCH 6/7] staging: ks7010: Factor out repeated code for reading IEs Quytelda Kahja
2018-03-23  5:07         ` [PATCH 7/7] staging: ks7010: Remove hostif_infrastructure_set2_request_t Quytelda Kahja
2018-03-16  6:30 [PATCH 2/6] staging: ks7010: Factor out code into helper methods Quytelda Kahja

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.