[PATCH 10/12] staging: ks7010: add variables key, key_index

Tobin C. Harding me at tobin.cc
Wed Mar 8 03:36:55 UTC 2017


'auth_type - 1' is used as an index into a key table. Adding a variable
appropriately named simplifies the code and adds meaning when
reading. Adding a pointer variable of type struct *kpa_key_t adds to
readability by removing the table access each time the key is used.

The key index is used to create a string so having it named adds
additional meaning when creating the string.

Declare variable 'key_index' and define it at declaration time. Declare
a pointer variable 'key' and define it to point to the correct key in
the key table.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 drivers/staging/ks7010/ks_hostif.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index 7dc0d99..7ff5345 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -318,6 +318,8 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv, unsigned int auth_t
 	struct mic_failure_t *mic_failure;
 	struct mihcael_mic_t mihcael_mic;
 	union iwreq_data wrqu;
+	unsigned int key_index = auth_type - 1;
+	struct wpa_key_t *key = priv->wpa.key[key_index];
 
 	eth_hdr = (struct ether_hdr *)(priv->rxp);
 	eth_proto = ntohs(eth_hdr->h_proto);
@@ -340,7 +342,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv, unsigned int auth_t
 			|| (auth_type == TYPE_GMK2
 				&& priv->wpa.group_suite ==
 				IW_AUTH_CIPHER_TKIP))
-		&& priv->wpa.key[auth_type - 1].key_len) {
+		&& key.key_len) {
 		DPRINTK(4, "TKIP: protocol=%04X: size=%u\n",
 			eth_proto, priv->rx_size);
 		/* MIC save */
@@ -348,7 +350,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv, unsigned int auth_t
 			(priv->rxp) + ((priv->rx_size) - 8), 8);
 		priv->rx_size = priv->rx_size - 8;
 		if (auth_type > 0 && auth_type < 4) {	/* auth_type check */
-			MichaelMICFunction(&mihcael_mic, (u8 *)priv->wpa.key[auth_type - 1].rx_mic_key, (u8 *)priv->rxp, (int)priv->rx_size, (u8)0,	/* priority */
+			MichaelMICFunction(&mihcael_mic, (u8 *)key.rx_mic_key, (u8 *)priv->rxp, (int)priv->rx_size, (u8)0,	/* priority */
 					(u8 *)mihcael_mic.Result);
 		}
 		if (memcmp(mihcael_mic.Result, recv_mic_buf, 8)) {
@@ -382,7 +384,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv, unsigned int auth_t
 			sprintf(wrqu_buf,
 				"MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
 				"%pM)",
-				auth_type - 1,
+				key_index,
 				eth_hdr->
 				h_dest[0] & 0x01 ? "broad" :
 				"uni", eth_hdr->h_source);
-- 
2.7.4



More information about the devel mailing list