2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 04:34:11 +08:00

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 <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Tobin C. Harding 2017-04-27 11:25:15 +10:00 committed by Greg Kroah-Hartman
parent 8cd1dbe1db
commit 08484ef419
2 changed files with 19 additions and 10 deletions

View File

@ -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 */

View File

@ -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 */
/* (SNAP+UI..) skip */
memcpy(skb_put(skb, rx_ind_size - 12), priv->rxp + 18,
rx_ind_size - 12); /* copy after Type */
size = ETH_ALEN * 2;
memcpy(skb_put(skb, size), priv->rxp, size);
aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 20);
/* (SNAP+UI..) skip */
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 &&
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); */