From 87bb326eada535ed72ca312878bb5ba69bad870b Mon Sep 17 00:00:00 2001 From: Aya Mahfouz Date: Sat, 11 Oct 2014 02:34:07 +0200 Subject: [PATCH] staging: vt6655: dpc.c: replace memcpy() by ether_addr_copy() using coccinelle This patch focuses on fixing the following warning generated by checkpatch.pl for the file dpc.c : Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2) The changes were applied using the following coccinelle rule: @@ expression e1, e2; @@ - memcpy(e1, e2, ETH_ALEN); + ether_addr_copy(e1, e2); According to ether_addr_copy() description and functionality, all Ethernet addresses should align to the u16 datatype. Here is the output of pahole for the relevant datastructures: struct tagS802_11Header { short unsigned int wFrameCtl; /* 0 2 */ short unsigned int wDurationID; /* 2 2 */ unsigned char abyAddr1[6]; /* 4 6 */ unsigned char abyAddr2[6]; /* 10 6 */ unsigned char abyAddr3[6]; /* 16 6 */ short unsigned int wSeqCtl; /* 22 2 */ unsigned char abyAddr4[6]; /* 24 6 */ /* size: 30, cachelines: 1, members: 7 */ /* last cacheline: 30 bytes */ }; struct iw_michaelmicfailure { __u32 flags; /* 0 4 */ struct sockaddr src_addr; /* 4 16 */ __u8 tsc[8]; /* 20 8 */ /* size: 28, cachelines: 1, members: 3 */ /* last cacheline: 28 bytes */ }; struct sockaddr { sa_family_t sa_family; /* 0 2 */ char sa_data[14]; /* 2 14 */ /* size: 16, cachelines: 1, members: 2 */ /* last cacheline: 16 bytes */ }; There is one thing to note though, sa_data is a char array of size 14. And the number of bytes copied using memcpy() or ether_addr_copy() is 6. Signed-off-by: Aya Mahfouz Signed-off-by: Greg Kroah-Hartman --- drivers/staging/vt6655/dpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/vt6655/dpc.c b/drivers/staging/vt6655/dpc.c index 8515b8c80801..344e12f1184e 100644 --- a/drivers/staging/vt6655/dpc.c +++ b/drivers/staging/vt6655/dpc.c @@ -742,7 +742,8 @@ device_receive_frame( } ev.src_addr.sa_family = ARPHRD_ETHER; - memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN); + ether_addr_copy(ev.src_addr.sa_data, + pMACHeader->abyAddr2); memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.length = sizeof(ev); wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev); -- 2.34.1