[OPW,kernel] staging: rtl8187se: Use ether_addr_copy function
diff mbox

Message ID 1b2b1f0854063cd47a3ff03aa7faeed375cc7475.1395085473.git.anarey@gmail.com
State New, archived
Headers show

Commit Message

Ana Rey March 17, 2014, 8:21 p.m. UTC
Use ether_addr_copy instead of memcpy function for fast copy an
Ethernet address in ieee80211/ieee80211_crypt_tkip.c

Fixes sparse warnings:
WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)

Signed-off-by: Ana Rey <anarey@gmail.com>
---
 drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Julia Lawall March 17, 2014, 10:03 p.m. UTC | #1
On Mon, 17 Mar 2014, Ana Rey wrote:

> Use ether_addr_copy instead of memcpy function for fast copy an
> Ethernet address in ieee80211/ieee80211_crypt_tkip.c

Are the fields aligned, as required by ether_addr_copy?  There is a tool
call pahole that can give you that information, but it works on the object
code, so it only works on the configuration used to compile the code.  If
the structure declaration contains ifdefs, there could be some cause for
concern.

julia

> Fixes sparse warnings:
> WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)
>
> Signed-off-by: Ana Rey <anarey@gmail.com>
> ---
>  drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
> index 6c1acc5..682a45c 100644
> --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
> +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
> @@ -23,6 +23,7 @@
>  #include <linux/crypto.h>
>  #include <linux/scatterlist.h>
>  #include <linux/crc32.h>
> +#include <linux/etherdevice.h>
>
>  MODULE_AUTHOR("Jouni Malinen");
>  MODULE_DESCRIPTION("Host AP crypt: TKIP");
> @@ -495,19 +496,19 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
>  	switch (le16_to_cpu(hdr11->frame_ctl) &
>  		(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
>  	case IEEE80211_FCTL_TODS:
> -		memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */
> +		ether_addr_copy(hdr, hdr11->addr3); /* DA */
>  		memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */
>  		break;
>  	case IEEE80211_FCTL_FROMDS:
> -		memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */
> +		ether_addr_copy(hdr, hdr11->addr1); /* DA */
>  		memcpy(hdr + ETH_ALEN, hdr11->addr3, ETH_ALEN); /* SA */
>  		break;
>  	case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
> -		memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */
> +		ether_addr_copy(hdr, hdr11->addr3); /* DA */
>  		memcpy(hdr + ETH_ALEN, hdr11->addr4, ETH_ALEN); /* SA */
>  		break;
>  	case 0:
> -		memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */
> +		ether_addr_copy(hdr, hdr11->addr1); /* DA */
>  		memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */
>  		break;
>  	}
> @@ -563,7 +564,7 @@ static void ieee80211_michael_mic_failure(struct net_device *dev,
>  	else
>  		ev.flags |= IW_MICFAILURE_PAIRWISE;
>  	ev.src_addr.sa_family = ARPHRD_ETHER;
> -	memcpy(ev.src_addr.sa_data, hdr->addr2, ETH_ALEN);
> +	ether_addr_copy(ev.src_addr.sa_data, hdr->addr2);
>  	memset(&wrqu, 0, sizeof(wrqu));
>  	wrqu.data.length = sizeof(ev);
>  	wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
> --
> 1.9.0
>
> --
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Patch
diff mbox

diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
index 6c1acc5..682a45c 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
@@ -23,6 +23,7 @@ 
 #include <linux/crypto.h>
 #include <linux/scatterlist.h>
 #include <linux/crc32.h>
+#include <linux/etherdevice.h>
 
 MODULE_AUTHOR("Jouni Malinen");
 MODULE_DESCRIPTION("Host AP crypt: TKIP");
@@ -495,19 +496,19 @@  static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
 	switch (le16_to_cpu(hdr11->frame_ctl) &
 		(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
 	case IEEE80211_FCTL_TODS:
-		memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */
+		ether_addr_copy(hdr, hdr11->addr3); /* DA */
 		memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */
 		break;
 	case IEEE80211_FCTL_FROMDS:
-		memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */
+		ether_addr_copy(hdr, hdr11->addr1); /* DA */
 		memcpy(hdr + ETH_ALEN, hdr11->addr3, ETH_ALEN); /* SA */
 		break;
 	case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
-		memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */
+		ether_addr_copy(hdr, hdr11->addr3); /* DA */
 		memcpy(hdr + ETH_ALEN, hdr11->addr4, ETH_ALEN); /* SA */
 		break;
 	case 0:
-		memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */
+		ether_addr_copy(hdr, hdr11->addr1); /* DA */
 		memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */
 		break;
 	}
@@ -563,7 +564,7 @@  static void ieee80211_michael_mic_failure(struct net_device *dev,
 	else
 		ev.flags |= IW_MICFAILURE_PAIRWISE;
 	ev.src_addr.sa_family = ARPHRD_ETHER;
-	memcpy(ev.src_addr.sa_data, hdr->addr2, ETH_ALEN);
+	ether_addr_copy(ev.src_addr.sa_data, hdr->addr2);
 	memset(&wrqu, 0, sizeof(wrqu));
 	wrqu.data.length = sizeof(ev);
 	wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);