netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] kernel: add byteorder macros with alignment fixups
@ 2008-03-20 17:34 Harvey Harrison
  2008-03-20 18:29 ` Al Viro
  2008-03-20 20:08 ` [RFC PATCH] kernel: add byteorder macros with alignment fixups H. Peter Anvin
  0 siblings, 2 replies; 11+ messages in thread
From: Harvey Harrison @ 2008-03-20 17:34 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, linux-netdev

A common pattern in the kernel (especially networking) is:

le32_to_cpu(get_unaligned((__le32 *)x));

Repeat for various combinations of le/be and 64/32/16 bit.  Add
a variant that operates on possibly unaligned pointers to
byteorder/generic.h

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 include/linux/byteorder/generic.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
index d377155..9b1a7a4 100644
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -73,6 +73,10 @@
  *	cpu_to_[bl]eXXp(__uXX x)
  *	[bl]eXX_to_cpup(__uXX x)
  *
+ * The same, but takes a possibly unaligned pointer to the value to convert
+ *	cpu_to_[bl]eXXp_un(__uXX x)
+ *	[bl]eXX_to_cpup_un(__uXX x)
+ *
  * The same, but change in situ
  *	cpu_to_[bl]eXXs(__uXX x)
  *	[bl]eXX_to_cpus(__uXX x)
@@ -84,6 +88,8 @@
 
 
 #if defined(__KERNEL__)
+#include <asm/unaligned.h>
+
 /*
  * inside the kernel, we can use nicknames;
  * outside of it, we must avoid POSIX namespace pollution...
@@ -126,6 +132,16 @@
 #define be16_to_cpus __be16_to_cpus
 
 /*
+ * Operates on possibly unaligned pointers
+ */
+#define le64_to_cpup_un(x) __le64_to_cpu(get_unaligned((__le64 *)(x)))
+#define le32_to_cpup_un(x) __le32_to_cpu(get_unaligned((__le32 *)(x)))
+#define le16_to_cpup_un(x) __le16_to_cpu(get_unaligned((__le16 *)(x)))
+#define be64_to_cpup_un(x) __be64_to_cpu(get_unaligned((__be64 *)(x)))
+#define be32_to_cpup_un(x) __be32_to_cpu(get_unaligned((__be32 *)(x)))
+#define be16_to_cpup_un(x) __be16_to_cpu(get_unaligned((__be16 *)(x)))
+
+/*
  * They have to be macros in order to do the constant folding
  * correctly - if the argument passed into a inline function
  * it is no longer constant according to gcc..
-- 
1.5.4.4.684.g0e08




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

end of thread, other threads:[~2008-03-24 16:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-20 17:34 [RFC PATCH] kernel: add byteorder macros with alignment fixups Harvey Harrison
2008-03-20 18:29 ` Al Viro
2008-03-20 18:37   ` Harvey Harrison
2008-03-20 19:09     ` Al Viro
2008-03-20 19:22       ` Harvey Harrison
2008-03-23 13:59         ` Pavel Machek
2008-03-24 16:35           ` Harvey Harrison
2008-03-20 19:41       ` [PATCH] kernel: add byteorder function " Harvey Harrison
2008-03-20 20:16       ` [PATCH] kernel: create linux/unaligned.h Harvey Harrison
2008-03-20 20:39         ` Randy Dunlap
2008-03-20 20:08 ` [RFC PATCH] kernel: add byteorder macros with alignment fixups H. Peter Anvin

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).