From b44907e64cc1987153f6577306108379be1523b7 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Tue, 8 May 2012 06:44:40 +0000 Subject: etherdev.h: Convert int is__ether_addr to bool Make the return value explicitly true or false. Signed-off-by: Joe Perches Signed-off-by: David S. Miller --- include/linux/etherdevice.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include/linux/etherdevice.h') diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index fe5136d81454..c47631fac229 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -59,7 +59,7 @@ extern struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, * * Return true if the address is all zeroes. */ -static inline int is_zero_ether_addr(const u8 *addr) +static inline bool is_zero_ether_addr(const u8 *addr) { return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); } @@ -71,7 +71,7 @@ static inline int is_zero_ether_addr(const u8 *addr) * Return true if the address is a multicast address. * By definition the broadcast address is also a multicast address. */ -static inline int is_multicast_ether_addr(const u8 *addr) +static inline bool is_multicast_ether_addr(const u8 *addr) { return 0x01 & addr[0]; } @@ -82,7 +82,7 @@ static inline int is_multicast_ether_addr(const u8 *addr) * * Return true if the address is a local address. */ -static inline int is_local_ether_addr(const u8 *addr) +static inline bool is_local_ether_addr(const u8 *addr) { return 0x02 & addr[0]; } @@ -93,7 +93,7 @@ static inline int is_local_ether_addr(const u8 *addr) * * Return true if the address is the broadcast address. */ -static inline int is_broadcast_ether_addr(const u8 *addr) +static inline bool is_broadcast_ether_addr(const u8 *addr) { return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; } @@ -104,7 +104,7 @@ static inline int is_broadcast_ether_addr(const u8 *addr) * * Return true if the address is a unicast address. */ -static inline int is_unicast_ether_addr(const u8 *addr) +static inline bool is_unicast_ether_addr(const u8 *addr) { return !is_multicast_ether_addr(addr); } @@ -118,7 +118,7 @@ static inline int is_unicast_ether_addr(const u8 *addr) * * Return true if the address is valid. */ -static inline int is_valid_ether_addr(const u8 *addr) +static inline bool is_valid_ether_addr(const u8 *addr) { /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to * explicitly check for it here. */ -- cgit v1.2.3 From a599b0f54d233d0f63d6be9a2ff0049d24751669 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Tue, 8 May 2012 18:56:45 +0000 Subject: etherdevice.h: Add ether_addr_equal Add a boolean function to check if 2 ethernet addresses are the same. This is to avoid any confusion about compare_ether_addr returning an unsigned, and not being able to use the compare_ether_addr function for sorting ala memcmp. Signed-off-by: Joe Perches Signed-off-by: David S. Miller --- include/linux/etherdevice.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/linux/etherdevice.h') diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index c47631fac229..f3301140d28a 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -171,6 +171,18 @@ static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0; } +/** + * ether_addr_equal - Compare two Ethernet addresses + * @addr1: Pointer to a six-byte array containing the Ethernet address + * @addr2: Pointer other six-byte array containing the Ethernet address + * + * Compare two ethernet addresses, returns true if equal + */ +static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) +{ + return !compare_ether_addr(addr1, addr2); +} + static inline unsigned long zap_last_2bytes(unsigned long value) { #ifdef __BIG_ENDIAN -- cgit v1.2.3 From baf523c9ba4a69e97b0b5a6fb0e0a9e43550a65b Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 9 May 2012 17:04:03 +0000 Subject: etherdevice.h: Add ether_addr_equal_64bits Add an optimized boolean function to check if 2 ethernet addresses are the same. This is to avoid any confusion about compare_ether_addr_64bits returning an unsigned, and not being able to use the compare_ether_addr_64bits function for sorting ala memcmp. Signed-off-by: Joe Perches Signed-off-by: David S. Miller --- include/linux/etherdevice.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/linux/etherdevice.h') diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index f3301140d28a..afacf8576d0f 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -224,6 +224,26 @@ static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], #endif } +/** + * ether_addr_equal_64bits - Compare two Ethernet addresses + * @addr1: Pointer to an array of 8 bytes + * @addr2: Pointer to an other array of 8 bytes + * + * Compare two ethernet addresses, returns true if equal, false otherwise. + * + * The function doesn't need any conditional branches and possibly uses + * word memory accesses on CPU allowing cheap unaligned memory reads. + * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} + * + * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. + */ + +static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], + const u8 addr2[6+2]) +{ + return !compare_ether_addr_64bits(addr1, addr2); +} + /** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure -- cgit v1.2.3 From e550ba1af9e7008ca8e22d85943cbdf0748c765c Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Fri, 11 May 2012 12:21:06 +0000 Subject: etherdevice: Remove now unused compare_ether_addr_64bits Move and invert the logic from the otherwise unused compare_ether_addr_64bits to ether_addr_equal_64bits. Neaten the logic in is_etherdev_addr. Signed-off-by: Joe Perches Signed-off-by: David S. Miller --- include/linux/etherdevice.h | 46 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) (limited to 'include/linux/etherdevice.h') diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index afacf8576d0f..dc85c1d2173b 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -193,12 +193,12 @@ static inline unsigned long zap_last_2bytes(unsigned long value) } /** - * compare_ether_addr_64bits - Compare two Ethernet addresses + * ether_addr_equal_64bits - Compare two Ethernet addresses * @addr1: Pointer to an array of 8 bytes * @addr2: Pointer to an other array of 8 bytes * - * Compare two ethernet addresses, returns 0 if equal, non-zero otherwise. - * Unlike memcmp(), it doesn't return a value suitable for sorting. + * Compare two ethernet addresses, returns true if equal, false otherwise. + * * The function doesn't need any conditional branches and possibly uses * word memory accesses on CPU allowing cheap unaligned memory reads. * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} @@ -206,44 +206,24 @@ static inline unsigned long zap_last_2bytes(unsigned long value) * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. */ -static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], - const u8 addr2[6+2]) +static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], + const u8 addr2[6+2]) { #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS unsigned long fold = ((*(unsigned long *)addr1) ^ (*(unsigned long *)addr2)); if (sizeof(fold) == 8) - return zap_last_2bytes(fold) != 0; + return zap_last_2bytes(fold) == 0; fold |= zap_last_2bytes((*(unsigned long *)(addr1 + 4)) ^ (*(unsigned long *)(addr2 + 4))); - return fold != 0; + return fold == 0; #else - return compare_ether_addr(addr1, addr2); + return ether_addr_equal(addr1, addr2); #endif } -/** - * ether_addr_equal_64bits - Compare two Ethernet addresses - * @addr1: Pointer to an array of 8 bytes - * @addr2: Pointer to an other array of 8 bytes - * - * Compare two ethernet addresses, returns true if equal, false otherwise. - * - * The function doesn't need any conditional branches and possibly uses - * word memory accesses on CPU allowing cheap unaligned memory reads. - * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} - * - * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. - */ - -static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], - const u8 addr2[6+2]) -{ - return !compare_ether_addr_64bits(addr1, addr2); -} - /** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure @@ -252,23 +232,23 @@ static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], * Compare passed address with all addresses of the device. Return true if the * address if one of the device addresses. * - * Note that this function calls compare_ether_addr_64bits() so take care of + * Note that this function calls ether_addr_equal_64bits() so take care of * the right padding. */ static inline bool is_etherdev_addr(const struct net_device *dev, const u8 addr[6 + 2]) { struct netdev_hw_addr *ha; - int res = 1; + bool res = false; rcu_read_lock(); for_each_dev_addr(dev, ha) { - res = compare_ether_addr_64bits(addr, ha->addr); - if (!res) + res = ether_addr_equal_64bits(addr, ha->addr); + if (res) break; } rcu_read_unlock(); - return !res; + return res; } #endif /* __KERNEL__ */ -- cgit v1.2.3 From 048b899ce38c3e1db88cb4464547090ef28630f8 Mon Sep 17 00:00:00 2001 From: stephen hemminger Date: Thu, 17 May 2012 05:17:28 +0000 Subject: etherdevice: fix comments Fix some minor problems in comments of etherdevice.h * Warning is out dated, file hasn't moved or disappeared in many years and is unlikely to do so soon. * Capitalize Ethernet consistently since it is a proper name * Fix descriptive comment of padding * Spelling and grammar fix for alignment comment Signed-off-by: Stephen Hemminger Signed-off-by: David S. Miller --- include/linux/etherdevice.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'include/linux/etherdevice.h') diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index dc85c1d2173b..3d406e0ede6d 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -18,8 +18,6 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * - * WARNING: This move may well be temporary. This file will get merged with others RSN. - * */ #ifndef _LINUX_ETHERDEVICE_H #define _LINUX_ETHERDEVICE_H @@ -159,7 +157,7 @@ static inline void eth_hw_addr_random(struct net_device *dev) * @addr1: Pointer to a six-byte array containing the Ethernet address * @addr2: Pointer other six-byte array containing the Ethernet address * - * Compare two ethernet addresses, returns 0 if equal, non-zero otherwise. + * Compare two Ethernet addresses, returns 0 if equal, non-zero otherwise. * Unlike memcmp(), it doesn't return a value suitable for sorting. */ static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) @@ -176,7 +174,7 @@ static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) * @addr1: Pointer to a six-byte array containing the Ethernet address * @addr2: Pointer other six-byte array containing the Ethernet address * - * Compare two ethernet addresses, returns true if equal + * Compare two Ethernet addresses, returns true if equal */ static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) { @@ -197,13 +195,13 @@ static inline unsigned long zap_last_2bytes(unsigned long value) * @addr1: Pointer to an array of 8 bytes * @addr2: Pointer to an other array of 8 bytes * - * Compare two ethernet addresses, returns true if equal, false otherwise. + * Compare two Ethernet addresses, returns true if equal, false otherwise. * * The function doesn't need any conditional branches and possibly uses * word memory accesses on CPU allowing cheap unaligned memory reads. - * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} + * arrays = { byte1, byte2, byte3, byte4, byte5, byte6, pad1, pad2 } * - * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. + * Please note that alignment of addr1 & addr2 are only guaranteed to be 16 bits. */ static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], @@ -257,7 +255,7 @@ static inline bool is_etherdev_addr(const struct net_device *dev, * @a: Pointer to Ethernet header * @b: Pointer to Ethernet header * - * Compare two ethernet headers, returns 0 if equal. + * Compare two Ethernet headers, returns 0 if equal. * This assumes that the network header (i.e., IP header) is 4-byte * aligned OR the platform can handle unaligned access. This is the * case for all packets coming into netif_receive_skb or similar -- cgit v1.2.3