Replace memcpy with ether_addr_copy and fix checkpatch warning
v3 cover Replace memcpy with ether_addr_copy and fix checkpatch warning
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(-)
Signature · 1 line
1.9.1
PATCH v3 1/4 Staging: rtl8192e: Replace memcpy with ether_addr_copy
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 */
};--- drivers/staging/rtl8192e/rtl819x_BAProc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtl819x_BAProc.c +3 -2
@@ -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 );
Signature · 1 line
1.9.1
Greg KH
maintainerRe: [Outreachy kernel] [PATCH v3 1/4] Staging: rtl8192e: Replace memcpy with ether_addr_copy
Quoted 13 lines · Darshana Padmadas
This patch fixes the following warning found by checkpatch.pl:
Preferether_addr_copy()overmemcpy()if the Ethernet addresses are __aligned(2Pahole showed that the structure for BAReq and Delba is aligned:
structrtllib_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 */
Quoted 8 lines
/* size: 24, cachelines: 1, members: 7 */ /* last cacheline: 24 bytes */ };Signed-off-by Darshana Padmadas <[email protected]>--- 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
PATCH v3 2/4 Staging: rtl8192e: Use ether_addr_copy instead of memcpy
In reply to Darshana PadmadasThis 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 */ };
--- drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +6 -6
@@ -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);
Signature · 1 line
1.9.1
PATCH v3 3/4 Staging: rtl8192e: Use ether_addr_copy replacing memcpy
In reply to Darshana PadmadasThis 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 */ };
--- drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8192e/rtllib_softmac.c +6 -6
@@ -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 ; }
Signature · 1 line
1.9.1
PATCH v3 4/4 Staging: rtl8192e: Use ether_addr_copy for aligned addresses
In reply to Darshana PadmadasThis 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 */
};--- drivers/staging/rtl8192e/rtllib_tx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8192e/rtllib_tx.c +3 -3
@@ -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 ); }
Signature · 1 line
1.9.1