Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1219684

[PATCHv2] staging: rtl8192u: r8192U_core: fix use ether_addr_copy() over memcpy() code style issue

From Raphaël Beamonte <raphael.beamonte@gmail.com>
Newsgroups linux.kernel
Subject [PATCHv2] staging: rtl8192u: r8192U_core: fix use ether_addr_copy() over memcpy() code style issue
Date 2015-09-06 04:20 +0200
Message-ID <q5xIJ-1Zz-3@gated-at.bofh.it> (permalink)
References <q5wjE-8h9-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Prefer ether_addr_copy() over memcpy() if the Ethernet addresses
are __aligned(2)

The values used are stored as dev_addr in net_device (declared in
include/linux/netdevice.h) and sa_data in sockaddr (declared in
include/linux/socket.h). Both these elements are u16 aligned as
shown by using pahole (position must be a multiple of sizeof(u16)):
unsigned char *            dev_addr;             /*   888     8 */
char                       sa_data[14];          /*     2    14 */

It is thus safe to use ether_addr_copy() instead of memcpy() for
that call, as it is already done in multiple files in the Linux
kernel sources:
  drivers/net/ethernet/broadcom/genet/bcmgenet.c
  drivers/net/ethernet/brocade/bna/bnad.c
  drivers/net/ethernet/emulex/benet/be_main.c
  drivers/net/ethernet/ezchip/nps_enet.c
  drivers/net/ethernet/ibm/ibmveth.c
  drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
  drivers/net/ethernet/intel/i40e/i40e_main.c
  drivers/net/ethernet/mellanox/mlx5/core/en_main.c
  drivers/net/usb/lan78xx.c
  net/8021q/vlan_dev.c
  net/batman-adv/soft-interface.c
  net/dsa/slave.c

Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
---
 drivers/staging/rtl8192u/r8192U_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 76255cb..b143b36 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -3469,7 +3469,7 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
 
 	down(&priv->wx_sem);
 
-	memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+	ether_addr_copy(dev->dev_addr, addr->sa_data);
 
 	schedule_work(&priv->reset_wq);
 	up(&priv->wx_sem);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: [PATCHv2 18/19] staging: rtl8192u: r8192U_core: fix use  ether_addr_copy() over memcpy() code style issue Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-09-03 19:10 +0200
  Re: [PATCHv2 18/19] staging: rtl8192u: r8192U_core: fix use  ether_addr_copy() over memcpy() code style issue Raphaël Beamonte <raphael.beamonte@gmail.com> - 2015-09-06 00:20 +0200
    Re: [PATCHv2 18/19] staging: rtl8192u: r8192U_core: fix use  ether_addr_copy() over memcpy() code style issue Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-09-06 02:50 +0200
      [PATCHv2] staging: rtl8192u: r8192U_core: fix use ether_addr_copy() over memcpy() code style issue Raphaël Beamonte <raphael.beamonte@gmail.com> - 2015-09-06 04:20 +0200

csiph-web