staging: vt6655: dpc.c: replace memcpy() by ether_addr_copy() using coccinelle

Author: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>

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 8515b8c..344e12f 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);
BtrLinux
Résumé de la politique de confidentialité

Ce site utilise des cookies afin que nous puissions vous fournir la meilleure expérience utilisateur possible. Les informations sur les cookies sont stockées dans votre navigateur et remplissent des fonctions telles que vous reconnaître lorsque vous revenez sur notre site Web et aider notre équipe à comprendre les sections du site que vous trouvez les plus intéressantes et utiles.