From 08484ef41927a52fbd0d46c5cd19a65535d768ea Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 27 Apr 2017 11:25:15 +1000 Subject: [PATCH] staging: ks7010: remove magic numbers Driver includes magic numbers. Defining constants or using existing constants aids the readability of the code. Magic number '12' is used for two ethernet addresses (6 bytes each). ETH_ALEN is already defined within the kernel to 6. We can us the expression '2 * ETH_ALEN' to make this code explicit. Magic number '20' refers to the data size, in bytes, of a struct ether_hdr (described in eap_packet.h). We can define a constant for this purpose, making the code explicit and easier to read. Define constant. Remove magic numbers, using newly defined constant and/or expression using existing kernel constant. Signed-off-by: Tobin C. Harding Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/eap_packet.h | 2 ++ drivers/staging/ks7010/ks_hostif.c | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/staging/ks7010/eap_packet.h b/drivers/staging/ks7010/eap_packet.h index 7a3decf66f88..b2d25ef1cd6b 100644 --- a/drivers/staging/ks7010/eap_packet.h +++ b/drivers/staging/ks7010/eap_packet.h @@ -9,6 +9,8 @@ #define ETH_ALEN 6 #endif +#define ETHER_HDR_SIZE 20 + struct ether_hdr { unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */ diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c index 7c20585edc50..8cfda6089b98 100644 --- a/drivers/staging/ks7010/ks_hostif.c +++ b/drivers/staging/ks7010/ks_hostif.c @@ -399,6 +399,7 @@ void hostif_data_indication(struct ks_wlan_private *priv) struct ether_hdr *eth_hdr; unsigned short eth_proto; struct ieee802_1x_hdr *aa1x_hdr; + size_t size; int ret; DPRINTK(3, "\n"); @@ -452,12 +453,15 @@ void hostif_data_indication(struct ks_wlan_private *priv) } DPRINTK(4, "SNAP, rx_ind_size = %d\n", rx_ind_size); - memcpy(skb_put(skb, 12), priv->rxp, 12); /* 8802/FDDI MAC copy */ + size = ETH_ALEN * 2; + memcpy(skb_put(skb, size), priv->rxp, size); + /* (SNAP+UI..) skip */ - memcpy(skb_put(skb, rx_ind_size - 12), priv->rxp + 18, - rx_ind_size - 12); /* copy after Type */ - aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 20); + size = rx_ind_size - (ETH_ALEN * 2); + memcpy(skb_put(skb, size), ð_hdr->h_proto, size); + + aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + ETHER_HDR_SIZE); if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY && priv->wpa.rsn_enabled) atomic_set(&priv->psstatus.snooze_guard, 1); @@ -1113,6 +1117,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb) struct ieee802_1x_hdr *aa1x_hdr; struct wpa_eapol_key *eap_key; struct ethhdr *eth; + size_t size; int ret; skb_len = skb->len; @@ -1164,11 +1169,13 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb) goto err_kfree; } - /* MAC address copy */ - memcpy(p, buffer, 12); /* DST/SRC MAC address */ - p += 12; - buffer += 12; - length -= 12; + /* dest and src MAC address copy */ + size = ETH_ALEN * 2; + memcpy(p, buffer, size); + p += size; + buffer += size; + length -= size; + /* EtherType/Length check */ if (*(buffer + 1) + (*buffer << 8) > 1500) { /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */ -- 2.20.1