diff options
author | Joe Perches <joe@perches.com> | 2014-01-14 18:18:47 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-15 18:39:33 -0500 |
commit | 286ab723d4b83d37deb4017008ef1444a95cfb0d (patch) | |
tree | 8d0887e7d7e40da36b0ae919558fc07cbf810430 | |
parent | a53d34c3465b8a840f7400932ae1b0a9f9ed6bef (diff) |
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>
-rw-r--r-- | include/linux/etherdevice.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index f344ac04f858..9c5529dc6d07 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h | |||
@@ -218,6 +218,28 @@ static inline void eth_hw_addr_random(struct net_device *dev) | |||
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 | * eth_hw_addr_inherit - Copy dev_addr from another net_device | 243 | * eth_hw_addr_inherit - Copy dev_addr from another net_device |
222 | * @dst: pointer to net_device to copy dev_addr to | 244 | * @dst: pointer to net_device to copy dev_addr to |
223 | * @src: pointer to net_device to copy dev_addr from | 245 | * @src: pointer to net_device to copy dev_addr from |
@@ -229,7 +251,7 @@ static inline void eth_hw_addr_inherit(struct net_device *dst, | |||
229 | struct net_device *src) | 251 | struct net_device *src) |
230 | { | 252 | { |
231 | dst->addr_assign_type = src->addr_assign_type; | 253 | dst->addr_assign_type = src->addr_assign_type; |
232 | memcpy(dst->dev_addr, src->dev_addr, ETH_ALEN); | 254 | ether_addr_copy(dst->dev_addr, src->dev_addr); |
233 | } | 255 | } |
234 | 256 | ||
235 | /** | 257 | /** |