netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add compare_ether_addr_unaligned
@ 2007-11-23  0:09 Daniel Drake
  2007-11-23  4:11 ` Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Daniel Drake @ 2007-11-23  0:09 UTC (permalink / raw)
  To: davem; +Cc: netdev

David Miller found a problem in a wireless driver where I was using
compare_ether_addr() on potentially unaligned data. Document that
compare_ether_addr() is not safe for use everywhere, and add an equivalent
function that works regardless of alignment.

Signed-off-by: Daniel Drake <dsd@gentoo.org>

Index: linux-2.6.24-rc3-git1/include/linux/etherdevice.h
===================================================================
--- linux-2.6.24-rc3-git1.orig/include/linux/etherdevice.h
+++ linux-2.6.24-rc3-git1/include/linux/etherdevice.h
@@ -123,11 +123,13 @@ static inline void random_ether_addr(u8 
 }
 
 /**
- * compare_ether_addr - Compare two Ethernet addresses
+ * compare_ether_addr - Compare two 16-bit-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 0 if equal
+ * Compare two ethernet addresses, returns 0 if equal. Both addresses must
+ * be 16-bit aligned. For unaligned or potentially unaligned address
+ * comparisons, use compare_ether_addr_unaligned() instead.
  */
 static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
 {
@@ -137,6 +139,21 @@ static inline unsigned compare_ether_add
 	BUILD_BUG_ON(ETH_ALEN != 6);
 	return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
 }
+
+/**
+ * compare_ether_addr_unaligned - 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 0 if equal. compare_ether_addr()
+ * is faster than this function, but unless you can ensure alignment you
+ * must use this function instead.
+ */
+static inline unsigned compare_ether_addr_unaligned(const u8 *addr1,
+						    const u8 *addr2)
+{
+	return memcmp(addr1, addr2, ETH_ALEN);
+}
 #endif	/* __KERNEL__ */
 
 #endif	/* _LINUX_ETHERDEVICE_H */

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2007-11-30  0:41 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-23  0:09 [PATCH] add compare_ether_addr_unaligned Daniel Drake
2007-11-23  4:11 ` Stephen Hemminger
2007-11-23 13:26 ` Herbert Xu
2007-11-26 10:39   ` Herbert Xu
2007-11-23 20:33 ` wireless vs. alignment requirements Johannes Berg
     [not found]   ` <1195850001.4149.165.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-11-24  6:15     ` Herbert Xu
2007-11-24  8:33       ` Johannes Berg
2007-11-24 13:32         ` Herbert Xu
     [not found]           ` <20071124133200.GA27531-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-24 13:49             ` Johannes Berg
2007-11-24 13:51               ` David Miller
2007-11-24 14:13               ` Herbert Xu
     [not found]                 ` <20071124141319.GA27819-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-24 20:11                   ` Stephen Hemminger
     [not found]                     ` <4748855C.5090103-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2007-11-24 21:33                       ` Johannes Berg
2007-11-25  1:08                       ` Herbert Xu
     [not found]                         ` <20071125010814.GD31668-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-25 21:21                           ` Stephen Hemminger
     [not found]                             ` <4749E768.9040002-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2007-11-26  1:38                               ` Herbert Xu
2007-11-27 17:16                         ` H. Peter Anvin
2007-11-27 17:16                       ` H. Peter Anvin
     [not found]                         ` <474C50D7.5010901-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
2007-11-27 18:39                           ` Stephen Hemminger
     [not found]                             ` <20071127103940.314c7844-s08KbqtN0aBORcJjwVk881hTQxXnIo14@public.gmane.org>
2007-11-28  2:42                               ` H. Peter Anvin
2007-11-29 13:11                           ` Herbert Xu
2007-11-29 17:50                             ` H. Peter Anvin
2007-11-30  0:26                               ` Herbert Xu
     [not found]                                 ` <20071130002621.GI23769-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-30  0:28                                   ` H. Peter Anvin
     [not found]                                     ` <474F5932.1030103-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
2007-11-30  0:34                                       ` Herbert Xu
     [not found]                                         ` <20071130003426.GJ23769-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-30  0:41                                           ` H. Peter Anvin
2007-11-24 21:13                   ` Johannes Berg
     [not found]                     ` <1195938799.4149.197.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-11-25  1:44                       ` Herbert Xu
     [not found]                         ` <20071125014446.GA32104-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2007-11-25 11:00                           ` Johannes Berg
     [not found]                             ` <1195988428.4149.225.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-11-25 11:22                               ` Herbert Xu
2007-11-25 13:54                                 ` Johannes Berg
     [not found]                                   ` <1195998864.4149.229.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-11-25 14:01                                     ` Herbert Xu
2007-11-25 17:04                                       ` Johannes Berg
     [not found]                                         ` <1196010257.4149.234.camel-YfaajirXv214zXjbi5bjpg@public.gmane.org>
2007-11-26  1:36                                           ` Herbert Xu
2007-11-24 13:11   ` Ulrich Kunitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).