[-next] etherdevice: Add ether_addr_equal_unaligned

Message ID 1386368461.31845.38.camel@joe-AO722 (mailing list archive)
State Accepted, archived
Headers

Commit Message

Joe Perches Dec. 6, 2013, 10:21 p.m. UTC
  Add a generic routine to test if possibly unaligned
to u16 Ethernet addresses are equal.

If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set,
this uses the slightly faster generic routine
ether_addr_equal, otherwise this uses memcmp.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/etherdevice.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
  

Comments

David Miller Dec. 10, 2013, 1:58 a.m. UTC | #1
From: Joe Perches <joe@perches.com>
Date: Fri, 06 Dec 2013 14:21:01 -0800

> Add a generic routine to test if possibly unaligned
> to u16 Ethernet addresses are equal.
> 
> If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set,
> this uses the slightly faster generic routine
> ether_addr_equal, otherwise this uses memcmp.
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Applied.
  

Patch

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 3526e81..eb36845 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -266,6 +266,24 @@  static inline bool ether_addr_equal_64bits(const u8 addr1[6+2],
 }
 
 /**
+ * ether_addr_equal_unaligned - Compare two not u16 aligned 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
+ *
+ * Please note: Use only when any Ethernet address may not be u16 aligned.
+ */
+static inline bool ether_addr_equal_unaligned(const u8 *addr1, const u8 *addr2)
+{
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
+	return ether_addr_equal(addr1, addr2);
+#else
+	return memcmp(addr1, addr2, ETH_ALEN) == 0;
+#endif
+}
+
+/**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure
  * @addr: Pointer to a six-byte array containing the Ethernet address