Commit 286ab723 authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

etherdevice: Use ether_addr_copy to copy an Ethernet address

Some systems can use the normally known u16 alignment of
Ethernet addresses to save some code/text bytes and cycles.

This does not change currently emitted code on x86 by gcc 4.8.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a53d34c3
...@@ -217,6 +217,28 @@ static inline void eth_hw_addr_random(struct net_device *dev) ...@@ -217,6 +217,28 @@ static inline void eth_hw_addr_random(struct net_device *dev)
eth_random_addr(dev->dev_addr); eth_random_addr(dev->dev_addr);
} }
/**
* ether_addr_copy - Copy an Ethernet address
* @dst: Pointer to a six-byte array Ethernet address destination
* @src: Pointer to a six-byte array Ethernet address source
*
* Please note: dst & src must both be aligned to u16.
*/
static inline void ether_addr_copy(u8 *dst, const u8 *src)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
*(u32 *)dst = *(const u32 *)src;
*(u16 *)(dst + 4) = *(const u16 *)(src + 4);
#else
u16 *a = (u16 *)dst;
const u16 *b = (const u16 *)src;
a[0] = b[0];
a[1] = b[1];
a[2] = b[2];
#endif
}
/** /**
* eth_hw_addr_inherit - Copy dev_addr from another net_device * eth_hw_addr_inherit - Copy dev_addr from another net_device
* @dst: pointer to net_device to copy dev_addr to * @dst: pointer to net_device to copy dev_addr to
...@@ -229,7 +251,7 @@ static inline void eth_hw_addr_inherit(struct net_device *dst, ...@@ -229,7 +251,7 @@ static inline void eth_hw_addr_inherit(struct net_device *dst,
struct net_device *src) struct net_device *src)
{ {
dst->addr_assign_type = src->addr_assign_type; dst->addr_assign_type = src->addr_assign_type;
memcpy(dst->dev_addr, src->dev_addr, ETH_ALEN); ether_addr_copy(dst->dev_addr, src->dev_addr);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment