All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning
@ 2015-03-27 15:47 Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy Darshana Padmadas
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Darshana Padmadas @ 2015-03-27 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Darshana Padmadas

This patch set replaces memcpy with ether_addr_copy if the
addresses of the structures are aligned. Structure layout is
shown by using the Pahole tool.

This patch set fixes the following warning reported by checkpatch:
WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2) 

Darshana Padmadas (4):
Changes in v3:
  - Abandoned patch 5/5 in v2 as it caused warnings during build.
  - Edited commit message in patch 3 to include structure layout.
  
  Staging: rtl8192e: Replace memcpy with ether_addr_copy
  Staging: rtl8192e: Use ether_addr_copy instead of memcpy
  Staging: rtl8192e: Use ether_addr_copy replacing memcpy
  Staging: rtl8192e: Use ether_addr_copy for aligned addresses

 drivers/staging/rtl8192e/rtl819x_BAProc.c    |  5 +++--
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 12 ++++++------
 drivers/staging/rtl8192e/rtllib_softmac.c    | 12 ++++++------
 drivers/staging/rtl8192e/rtllib_tx.c         |  6 +++---
 4 files changed, 18 insertions(+), 17 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy
  2015-03-27 15:47 [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning Darshana Padmadas
@ 2015-03-27 15:47 ` Darshana Padmadas
  2015-04-01 15:28   ` [Outreachy kernel] " Greg KH
  2015-03-27 15:47 ` [PATCH v3 2/4] Staging: rtl8192e: Use ether_addr_copy instead of memcpy Darshana Padmadas
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Darshana Padmadas @ 2015-03-27 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Darshana Padmadas

This patch fixes the following warning found by checkpatch.pl:
Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2

Pahole showed that the structure for BAReq and Delba is aligned:
struct rtllib_hdr_3addr {
        __le16                     frame_ctl;            /*     0     2 */
        __le16                     duration_id;          /*     2     2 */
        u8                         addr1[6];             /*     4     6 */
        u8                         addr2[6];             /*    10     6 */
        u8                         addr3[6];             /*    16     6 */
        __le16                     seq_ctl;              /*    22     2 */
        u8                         payload[0];           /*    24     0 */

        /* size: 24, cachelines: 1, members: 7 */
        /* last cacheline: 24 bytes */
};

Signed-off-by: Darshana Padmadas <darshanapadmadas@gmail.com>
---
 drivers/staging/rtl8192e/rtl819x_BAProc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl819x_BAProc.c b/drivers/staging/rtl8192e/rtl819x_BAProc.c
index 0415e02..4031462 100644
--- a/drivers/staging/rtl8192e/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_BAProc.c
@@ -18,6 +18,7 @@
 ******************************************************************************/
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
+#include <linux/etherdevice.h>
 #include "rtllib.h"
 #include "rtl819x_BA.h"
 
@@ -103,7 +104,7 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst,
 	BAReq = (struct rtllib_hdr_3addr *)skb_put(skb,
 		 sizeof(struct rtllib_hdr_3addr));
 
-	memcpy(BAReq->addr1, Dst, ETH_ALEN);
+	ether_addr_copy(BAReq->addr1, Dst);
 	memcpy(BAReq->addr2, ieee->dev->dev_addr, ETH_ALEN);
 
 	memcpy(BAReq->addr3, ieee->current_network.bssid, ETH_ALEN);
@@ -168,7 +169,7 @@ static struct sk_buff *rtllib_DELBA(struct rtllib_device *ieee, u8 *dst,
 	Delba = (struct rtllib_hdr_3addr *) skb_put(skb,
 		 sizeof(struct rtllib_hdr_3addr));
 
-	memcpy(Delba->addr1, dst, ETH_ALEN);
+	ether_addr_copy(Delba->addr1, dst);
 	memcpy(Delba->addr2, ieee->dev->dev_addr, ETH_ALEN);
 	memcpy(Delba->addr3, ieee->current_network.bssid, ETH_ALEN);
 	Delba->frame_ctl = cpu_to_le16(RTLLIB_STYPE_MANAGE_ACT);
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/4] Staging: rtl8192e: Use ether_addr_copy instead of memcpy
  2015-03-27 15:47 [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy Darshana Padmadas
@ 2015-03-27 15:47 ` Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 3/4] Staging: rtl8192e: Use ether_addr_copy replacing memcpy Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 4/4] Staging: rtl8192e: Use ether_addr_copy for aligned addresses Darshana Padmadas
  3 siblings, 0 replies; 6+ messages in thread
From: Darshana Padmadas @ 2015-03-27 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Darshana Padmadas

This patch replaces use of memcpy with ether_addr_copy since
the addresses for struct of hdr11 and ev are aligned as shown by Pahole
and hdr is of type u8.
The header file linux/etherdevice.h is also included where
ether_addr_copy is defined.

struct rtllib_hdr_4addr {
        __le16                     frame_ctl;            /*     0     2 */
        __le16                     duration_id;          /*     2     2 */
        u8                         addr1[6];             /*     4     6 */
        u8                         addr2[6];             /*    10     6 */
        u8                         addr3[6];             /*    16     6 */
        __le16                     seq_ctl;              /*    22     2 */
        u8                         addr4[6];             /*    24     6 */
        u8                         payload[0];           /*    30     0 */

        /* size: 30, cachelines: 1, members: 8 */
        /* 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 */
};

Signed-off-by: Darshana Padmadas <darshanapadmadas@gmail.com>
---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_crypt_tkip.c b/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
index 78db2b6..949fc8f 100644
--- a/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
+++ b/drivers/staging/rtl8192e/rtllib_crypt_tkip.c
@@ -21,7 +21,7 @@
 #include <linux/crypto.h>
 #include <linux/scatterlist.h>
 #include <linux/crc32.h>
-
+#include <linux/etherdevice.h>
 #include "rtllib.h"
 
 struct rtllib_tkip_data {
@@ -525,19 +525,19 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
 	switch (le16_to_cpu(hdr11->frame_ctl) &
 		(RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
 	case RTLLIB_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 RTLLIB_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 RTLLIB_FCTL_FROMDS | RTLLIB_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;
 	}
@@ -591,7 +591,7 @@ static void rtllib_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.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 3/4] Staging: rtl8192e: Use ether_addr_copy replacing memcpy
  2015-03-27 15:47 [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 2/4] Staging: rtl8192e: Use ether_addr_copy instead of memcpy Darshana Padmadas
@ 2015-03-27 15:47 ` Darshana Padmadas
  2015-03-27 15:47 ` [PATCH v3 4/4] Staging: rtl8192e: Use ether_addr_copy for aligned addresses Darshana Padmadas
  3 siblings, 0 replies; 6+ messages in thread
From: Darshana Padmadas @ 2015-03-27 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Darshana Padmadas

This patch uses ether_addr_copy instead of memcpy since
the structures of beacon_buf, assoc, auth, a, header, a
are aligned as shown by Pahole:

struct rtllib_probe_response {
        struct rtllib_hdr_3addr    header;               /*     0    24 */
        u32                        time_stamp[2];        /*    24     8 */
        __le16                     beacon_interval;      /*    32     2 */
        __le16                     capability;           /*    34     2 */
        struct rtllib_info_element info_element[0];      /*    36     0 */

        /* size: 36, cachelines: 1, members: 5 */
        /* last cacheline: 36 bytes */
};
struct rtllib_assoc_response_frame {
        struct rtllib_hdr_3addr    header;               /*     0    24 */
        __le16                     capability;           /*    24     2 */
        __le16                     status;               /*    26     2 */
        __le16                     aid;                  /*    28     2 */
        struct rtllib_info_element info_element[0];      /*    30     0 */

        /* size: 30, cachelines: 1, members: 5 */
        /* last cacheline: 30 bytes */
};
struct rtllib_authentication {
        struct rtllib_hdr_3addr    header;               /*     0    24 */
        __le16                     algorithm;            /*    24     2 */
        __le16                     transaction;          /*    26     2 */
        __le16                     status;               /*    28     2 */
        struct rtllib_info_element info_element[0];      /*    30     0 */

        /* size: 30, cachelines: 1, members: 5 */
        /* last cacheline: 30 bytes */
};
struct rtllib_hdr_3addr {
        __le16                     frame_ctl;            /*     0     2 */
        __le16                     duration_id;          /*     2     2 */
        u8                         addr1[6];             /*     4     6 */
        u8                         addr2[6];             /*    10     6 */
        u8                         addr3[6];             /*    16     6 */
        __le16                     seq_ctl;              /*    22     2 */
        u8                         payload[0];           /*    24     0 */

        /* size: 24, cachelines: 1, members: 7 */
        /* last cacheline: 24 bytes */
};
struct rtllib_assoc_request_frame {
	struct rtllib_hdr_3addr    header;               /*     0    24 */
	__le16                     capability;           /*    24     2 */
	__le16                     listen_interval;      /*    26     2 */
	struct rtllib_info_element info_element[0];      /*    28     0 */

	/* size: 28, cachelines: 1, members: 4 */
	/* last cacheline: 28 bytes */
};

Signed-off-by: Darshana Padmadas <darshanapadmadas@gmail.com>
---
 drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 16aef7c..d2ea955 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -911,7 +911,7 @@ static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, u8 *dest)
 
 	beacon_buf = (struct rtllib_probe_response *) skb_put(skb,
 		     (beacon_size - ieee->tx_headroom));
-	memcpy(beacon_buf->header.addr1, dest, ETH_ALEN);
+	ether_addr_copy(beacon_buf->header.addr1, dest);
 	memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
 	memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
 
@@ -1008,7 +1008,7 @@ static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest)
 		skb_put(skb, sizeof(struct rtllib_assoc_response_frame));
 
 	assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP);
-	memcpy(assoc->header.addr1, dest, ETH_ALEN);
+	ether_addr_copy(assoc->header.addr1, dest);
 	memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
 	memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
 	assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
@@ -1067,7 +1067,7 @@ static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status,
 
 	memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
 	memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
-	memcpy(auth->header.addr1, dest, ETH_ALEN);
+	ether_addr_copy(auth->header.addr1, dest);
 	auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH);
 	return skb;
 
@@ -1831,7 +1831,7 @@ static int auth_rq_parse(struct sk_buff *skb, u8 *dest)
 	}
 	a = (struct rtllib_authentication *) skb->data;
 
-	memcpy(dest, a->header.addr2, ETH_ALEN);
+	ether_addr_copy(dest, a->header.addr2);
 
 	if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
 		return  WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
@@ -1859,7 +1859,7 @@ static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb,
 	if (bssid_match)
 		return -1;
 
-	memcpy(src, header->addr2, ETH_ALEN);
+	ether_addr_copy(src, header->addr2);
 
 	skbend = (u8 *)skb->data + skb->len;
 
@@ -1898,7 +1898,7 @@ static int assoc_rq_parse(struct sk_buff *skb, u8 *dest)
 
 	a = (struct rtllib_assoc_request_frame *) skb->data;
 
-	memcpy(dest, a->header.addr2, ETH_ALEN);
+	ether_addr_copy(dest, a->header.addr2);
 
 	return 0;
 }
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 4/4] Staging: rtl8192e: Use ether_addr_copy for aligned addresses
  2015-03-27 15:47 [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning Darshana Padmadas
                   ` (2 preceding siblings ...)
  2015-03-27 15:47 ` [PATCH v3 3/4] Staging: rtl8192e: Use ether_addr_copy replacing memcpy Darshana Padmadas
@ 2015-03-27 15:47 ` Darshana Padmadas
  3 siblings, 0 replies; 6+ messages in thread
From: Darshana Padmadas @ 2015-03-27 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Darshana Padmadas

This patch replaces memcpy with ether_addr_copy since structures
are aligned as shown by pahole:
struct rtllib_hdr_3addrqos {
        __le16                     frame_ctl;            /*     0     2 */
        __le16                     duration_id;          /*     2     2 */
        u8                         addr1[6];             /*     4     6 */
        u8                         addr2[6];             /*    10     6 */
        u8                         addr3[6];             /*    16     6 */
        __le16                     seq_ctl;              /*    22     2 */
        __le16                     qos_ctl;              /*    24     2 */
        u8                         payload[0];           /*    26     0 */

        /* size: 26, cachelines: 1, members: 8 */
        /* last cacheline: 26 bytes */
};

Signed-off-by: Darshana Padmadas <darshanapadmadas@gmail.com>
---
 drivers/staging/rtl8192e/rtllib_tx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
index 4f68ffe..de74e0e 100644
--- a/drivers/staging/rtl8192e/rtllib_tx.c
+++ b/drivers/staging/rtl8192e/rtllib_tx.c
@@ -688,12 +688,12 @@ int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
 				memcpy(&header.addr3,
 				       ieee->current_network.bssid, ETH_ALEN);
 			else
-				memcpy(&header.addr3, &dest, ETH_ALEN);
+				ether_addr_copy(&header.addr3, &dest);
 		} else if (ieee->iw_mode == IW_MODE_ADHOC) {
 			/* not From/To DS: Addr1 = DA, Addr2 = SA,
 			Addr3 = BSSID */
-			memcpy(&header.addr1, dest, ETH_ALEN);
-			memcpy(&header.addr2, src, ETH_ALEN);
+			ether_addr_copy(&header.addr1, dest);
+			ether_addr_copy(&header.addr2, src);
 			memcpy(&header.addr3, ieee->current_network.bssid,
 			       ETH_ALEN);
 		}
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy
  2015-03-27 15:47 ` [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy Darshana Padmadas
@ 2015-04-01 15:28   ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2015-04-01 15:28 UTC (permalink / raw)
  To: Darshana Padmadas; +Cc: outreachy-kernel

On Fri, Mar 27, 2015 at 09:17:04PM +0530, Darshana Padmadas wrote:
> This patch fixes the following warning found by checkpatch.pl:
> Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2
> 
> Pahole showed that the structure for BAReq and Delba is aligned:
> struct rtllib_hdr_3addr {
>         __le16                     frame_ctl;            /*     0     2 */
>         __le16                     duration_id;          /*     2     2 */
>         u8                         addr1[6];             /*     4     6 */
>         u8                         addr2[6];             /*    10     6 */
>         u8                         addr3[6];             /*    16     6 */
>         __le16                     seq_ctl;              /*    22     2 */
>         u8                         payload[0];           /*    24     0 */
> 
>         /* size: 24, cachelines: 1, members: 7 */
>         /* last cacheline: 24 bytes */
> };
> 
> Signed-off-by: Darshana Padmadas <darshanapadmadas@gmail.com>
> ---
>  drivers/staging/rtl8192e/rtl819x_BAProc.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

One of the patches in this series causes a bunch of build warnings,
which means you didn't test build them :(

So I can't take these, please fix them up, TEST THEM, and then resend.

thanks,

greg k-h


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-01 15:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-27 15:47 [PATCH v3 0/4] Replace memcpy with ether_addr_copy and fix checkpatch warning Darshana Padmadas
2015-03-27 15:47 ` [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy Darshana Padmadas
2015-04-01 15:28   ` [Outreachy kernel] " Greg KH
2015-03-27 15:47 ` [PATCH v3 2/4] Staging: rtl8192e: Use ether_addr_copy instead of memcpy Darshana Padmadas
2015-03-27 15:47 ` [PATCH v3 3/4] Staging: rtl8192e: Use ether_addr_copy replacing memcpy Darshana Padmadas
2015-03-27 15:47 ` [PATCH v3 4/4] Staging: rtl8192e: Use ether_addr_copy for aligned addresses Darshana Padmadas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.