Commit 08484ef4 authored by Tobin C. Harding's avatar Tobin C. Harding Committed by Greg Kroah-Hartman

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: default avatarTobin C. Harding <me@tobin.cc>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8cd1dbe1
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#define ETH_ALEN 6 #define ETH_ALEN 6
#endif #endif
#define ETHER_HDR_SIZE 20
struct ether_hdr { struct ether_hdr {
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
unsigned char h_source[ETH_ALEN]; /* source ether addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */
......
...@@ -399,6 +399,7 @@ void hostif_data_indication(struct ks_wlan_private *priv) ...@@ -399,6 +399,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
struct ether_hdr *eth_hdr; struct ether_hdr *eth_hdr;
unsigned short eth_proto; unsigned short eth_proto;
struct ieee802_1x_hdr *aa1x_hdr; struct ieee802_1x_hdr *aa1x_hdr;
size_t size;
int ret; int ret;
DPRINTK(3, "\n"); DPRINTK(3, "\n");
...@@ -452,12 +453,15 @@ void hostif_data_indication(struct ks_wlan_private *priv) ...@@ -452,12 +453,15 @@ void hostif_data_indication(struct ks_wlan_private *priv)
} }
DPRINTK(4, "SNAP, rx_ind_size = %d\n", rx_ind_size); 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 */ /* (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), &eth_hdr->h_proto, size);
aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + ETHER_HDR_SIZE);
if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY && if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
priv->wpa.rsn_enabled) priv->wpa.rsn_enabled)
atomic_set(&priv->psstatus.snooze_guard, 1); atomic_set(&priv->psstatus.snooze_guard, 1);
...@@ -1113,6 +1117,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb) ...@@ -1113,6 +1117,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
struct ieee802_1x_hdr *aa1x_hdr; struct ieee802_1x_hdr *aa1x_hdr;
struct wpa_eapol_key *eap_key; struct wpa_eapol_key *eap_key;
struct ethhdr *eth; struct ethhdr *eth;
size_t size;
int ret; int ret;
skb_len = skb->len; skb_len = skb->len;
...@@ -1164,11 +1169,13 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb) ...@@ -1164,11 +1169,13 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
goto err_kfree; goto err_kfree;
} }
/* MAC address copy */ /* dest and src MAC address copy */
memcpy(p, buffer, 12); /* DST/SRC MAC address */ size = ETH_ALEN * 2;
p += 12; memcpy(p, buffer, size);
buffer += 12; p += size;
length -= 12; buffer += size;
length -= size;
/* EtherType/Length check */ /* EtherType/Length check */
if (*(buffer + 1) + (*buffer << 8) > 1500) { if (*(buffer + 1) + (*buffer << 8) > 1500) {
/* ProtocolEAP = *(buffer+1) + (*buffer << 8); */ /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment