Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Joe Perches and committed by
David S. Miller
286ab723 a53d34c3

+23 -1
+23 -1
include/linux/etherdevice.h
··· 218 218 } 219 219 220 220 /** 221 + * ether_addr_copy - Copy an Ethernet address 222 + * @dst: Pointer to a six-byte array Ethernet address destination 223 + * @src: Pointer to a six-byte array Ethernet address source 224 + * 225 + * Please note: dst & src must both be aligned to u16. 226 + */ 227 + static inline void ether_addr_copy(u8 *dst, const u8 *src) 228 + { 229 + #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) 230 + *(u32 *)dst = *(const u32 *)src; 231 + *(u16 *)(dst + 4) = *(const u16 *)(src + 4); 232 + #else 233 + u16 *a = (u16 *)dst; 234 + const u16 *b = (const u16 *)src; 235 + 236 + a[0] = b[0]; 237 + a[1] = b[1]; 238 + a[2] = b[2]; 239 + #endif 240 + } 241 + 242 + /** 221 243 * eth_hw_addr_inherit - Copy dev_addr from another net_device 222 244 * @dst: pointer to net_device to copy dev_addr to 223 245 * @src: pointer to net_device to copy dev_addr from ··· 251 229 struct net_device *src) 252 230 { 253 231 dst->addr_assign_type = src->addr_assign_type; 254 - memcpy(dst->dev_addr, src->dev_addr, ETH_ALEN); 232 + ether_addr_copy(dst->dev_addr, src->dev_addr); 255 233 } 256 234 257 235 /**