[OPW,kernel] Staging: rtl8192e: rtllib_rx: Prefer ether_addr_copy() over memcpy()
diff mbox

Message ID 1414692352-3479-1-git-send-email-anuv.1994@gmail.com
State New, archived
Headers show

Commit Message

anuvazhayil Oct. 30, 2014, 6:05 p.m. UTC
Fixed the checkpatch.pl warning in rtllib_rx.c file
WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)

Signed-off-by: anuvazhayil <anuv.1994@gmail.com>
---
 drivers/staging/rtl8192e/rtllib_rx.c | 68 +++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 29 deletions(-)

Comments

Greg Kroah-Hartman Oct. 30, 2014, 8:18 p.m. UTC | #1
On Thu, Oct 30, 2014 at 11:35:52PM +0530, anuvazhayil wrote:
> Fixed the checkpatch.pl warning in rtllib_rx.c file
> WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)
> 
> Signed-off-by: anuvazhayil <anuv.1994@gmail.com>
> ---
>  drivers/staging/rtl8192e/rtllib_rx.c | 68 +++++++++++++++++++++---------------
>  1 file changed, 39 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
> index 1c2014f..0c0f196 100644
> --- a/drivers/staging/rtl8192e/rtllib_rx.c
> +++ b/drivers/staging/rtl8192e/rtllib_rx.c
> @@ -140,8 +140,8 @@ rtllib_frag_cache_get(struct rtllib_device *ieee,
>  		entry->seq = seq;
>  		entry->last_frag = frag;
>  		entry->skb = skb;
> -		memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
> -		memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
> +		ether_addr_copy(entry->src_addr, hdr->addr2);
> +		ether_addr_copy(entry->dst_addr, hdr->addr1);

You need to prove that they are aligned.  Have you done that?

Patch
diff mbox

diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 1c2014f..0c0f196 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -140,8 +140,8 @@  rtllib_frag_cache_get(struct rtllib_device *ieee,
 		entry->seq = seq;
 		entry->last_frag = frag;
 		entry->skb = skb;
-		memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
-		memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
+		ether_addr_copy(entry->src_addr, hdr->addr2);
+		ether_addr_copy(entry->dst_addr, hdr->addr1);
 	} else {
 		/* received a fragment of a frame for which the head fragment
 		 * should have already been received */
@@ -403,7 +403,7 @@  static int is_duplicate_packet(struct rtllib_device *ieee,
 				printk(KERN_WARNING "Cannot malloc new mac entry\n");
 				return 0;
 			}
-			memcpy(entry->mac, mac, ETH_ALEN);
+			ether_addr_copy(entry->mac, mac);
 			entry->seq_num[tid] = seq;
 			entry->frag_num[tid] = frag;
 			entry->packet_time[tid] = jiffies;
@@ -490,15 +490,19 @@  void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prx
 				/* remove RFC1042 or Bridge-Tunnel encapsulation
 				 * and replace EtherType */
 				skb_pull(sub_skb, SNAP_SIZE);
-				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
-				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						prxb->src);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						prxb->dst);
 			} else {
 				u16 len;
 			/* Leave Ethernet header part of hdr and full payload */
 				len = sub_skb->len;
 				memcpy(skb_push(sub_skb, 2), &len, 2);
-				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
-				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						prxb->src);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						prxb->dst);
 			}
 
 			/* Indicate the packets to upper layer */
@@ -794,14 +798,14 @@  static u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
 
 		rxb->subframes[0] = sub_skb;
 
-		memcpy(rxb->src, src, ETH_ALEN);
-		memcpy(rxb->dst, dst, ETH_ALEN);
+		ether_addr_copy(rxb->src, src);
+		ether_addr_copy(rxb->dst, dst);
 		rxb->subframes[0]->dev = ieee->dev;
 		return 1;
 	} else {
 		rxb->nr_subframes = 0;
-		memcpy(rxb->src, src, ETH_ALEN);
-		memcpy(rxb->dst, dst, ETH_ALEN);
+		ether_addr_copy(rxb->src, src);
+		ether_addr_copy(rxb->dst, dst);
 		while (skb->len > ETHERNET_HEADER_SIZE) {
 			/* Offset 12 denote 2 mac address */
 			nSubframe_Length = *((u16 *)(skb->data + 12));
@@ -939,24 +943,24 @@  static void rtllib_rx_extract_addr(struct rtllib_device *ieee,
 
 	switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
 	case RTLLIB_FCTL_FROMDS:
-		memcpy(dst, hdr->addr1, ETH_ALEN);
-		memcpy(src, hdr->addr3, ETH_ALEN);
-		memcpy(bssid, hdr->addr2, ETH_ALEN);
+		ether_addr_copy(dst, hdr->addr1);
+		ether_addr_copy(src, hdr->addr3);
+		ether_addr_copy(bssid, hdr->addr2);
 		break;
 	case RTLLIB_FCTL_TODS:
-		memcpy(dst, hdr->addr3, ETH_ALEN);
-		memcpy(src, hdr->addr2, ETH_ALEN);
-		memcpy(bssid, hdr->addr1, ETH_ALEN);
+		ether_addr_copy(dst, hdr->addr3);
+		ether_addr_copy(src, hdr->addr2);
+		ether_addr_copy(bssid, hdr->addr1);
 		break;
 	case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
-		memcpy(dst, hdr->addr3, ETH_ALEN);
-		memcpy(src, hdr->addr4, ETH_ALEN);
-		memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
+		ether_addr_copy(dst, hdr->addr3);
+		ether_addr_copy(src, hdr->addr4);
+		ether_addr_copy(bssid, ieee->current_network.bssid);
 		break;
 	case 0:
-		memcpy(dst, hdr->addr1, ETH_ALEN);
-		memcpy(src, hdr->addr2, ETH_ALEN);
-		memcpy(bssid, hdr->addr3, ETH_ALEN);
+		ether_addr_copy(dst, hdr->addr1);
+		ether_addr_copy(src, hdr->addr2);
+		ether_addr_copy(bssid, hdr->addr3);
 		break;
 	}
 }
@@ -1227,15 +1231,19 @@  static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
 				/* remove RFC1042 or Bridge-Tunnel encapsulation and
 				 * replace EtherType */
 				skb_pull(sub_skb, SNAP_SIZE);
-				memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
-				memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						src);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						dst);
 			} else {
 				u16 len;
 				/* Leave Ethernet header part of hdr and full payload */
 				len = sub_skb->len;
 				memcpy(skb_push(sub_skb, 2), &len, 2);
-				memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
-				memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						src);
+				ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+						dst);
 			}
 
 			ieee->stats.rx_packets++;
@@ -2070,7 +2078,8 @@  int rtllib_parse_info_param(struct rtllib_device *ieee,
 					if (network->MBssidMask != 0) {
 						network->bMBssidValid = true;
 						network->MBssidMask = 0xff << (network->MBssidMask);
-						memcpy(network->MBssid, network->bssid, ETH_ALEN);
+						ether_addr_copy(network->MBssid,
+								network->bssid);
 						network->MBssid[5] &= network->MBssidMask;
 					} else {
 						network->bMBssidValid = false;
@@ -2265,7 +2274,8 @@  static inline int rtllib_network_init(
 	memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
 
 	/* Pull out fixed field data */
-	memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
+	ether_addr_copy(network->bssid,
+			beacon->header.addr3);
 	network->capability = le16_to_cpu(beacon->capability);
 	network->last_scanned = jiffies;
 	network->time_stamp[0] = beacon->time_stamp[0];