]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: vt6655: dpc.c: replace memcpy() by ether_addr_copy() using coccinelle
authorAya Mahfouz <mahfouz.saif.elyazal@gmail.com>
Sat, 11 Oct 2014 00:34:07 +0000 (02:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Oct 2014 02:30:15 +0000 (10:30 +0800)
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 <mahfouz.saif.elyazal@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vt6655/dpc.c

index 8515b8c808017e7697ce8de26f5efe2683d2f4db..344e12f1184effaa0bbf6f69bcbe0dd6f2a30deb 100644 (file)
@@ -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);