staging: ks7010: add variables key, key_index
authorTobin C. Harding <me@tobin.cc>
Mon, 13 Mar 2017 06:38:22 +0000 (17:38 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 13 Mar 2017 22:20:06 +0000 (06:20 +0800)
'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@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks_hostif.c

index a93b104a5116b1e4e174bb522d39157e13eee72f..310928fe29912b70319996ba02c82ae19c79be0d 100644 (file)
@@ -319,6 +319,8 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
        struct mic_failure_t *mic_failure;
        struct michel_mic_t michel_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);
@@ -338,7 +340,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
              priv->wpa.group_suite == IW_AUTH_CIPHER_TKIP) ||
             (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 */
@@ -346,7 +348,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
                priv->rx_size = priv->rx_size - 8;
                if (auth_type > 0 && auth_type < 4) {   /* auth_type check */
                        MichaelMICFunction(&michel_mic,
-                                          (uint8_t *)priv->wpa.key[auth_type - 1].rx_mic_key,
+                                          (uint8_t *)key->rx_mic_key,
                                           (uint8_t *)priv->rxp,
                                           (int)priv->rx_size,
                                           (uint8_t)0,  /* priority */
@@ -376,7 +378,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
                        /*  needed parameters: count, keyid, key type, TSC */
                        sprintf(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);
                        memset(&wrqu, 0, sizeof(wrqu));