public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Miller <davem@davemloft.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] byteorder: force in-place endian conversion to always evaluate args
Date: Fri, 25 Jul 2008 09:33:41 -0700	[thread overview]
Message-ID: <1217003621.5971.4.camel@brick> (raw)

David Miller reported breakage in ide when the in-place byteorder helpers
were used as the macros do not always evaluate their args which led to
an infinite loop.

Just make them functions to ensure they always do so.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 include/linux/byteorder/big_endian.h    |   60 ++++++++++++++++++++++++------
 include/linux/byteorder/little_endian.h |   60 ++++++++++++++++++++++++------
 2 files changed, 96 insertions(+), 24 deletions(-)

diff --git a/include/linux/byteorder/big_endian.h b/include/linux/byteorder/big_endian.h
index 961ed4b..b53ccd0 100644
--- a/include/linux/byteorder/big_endian.h
+++ b/include/linux/byteorder/big_endian.h
@@ -88,18 +88,54 @@ static inline __u16 __be16_to_cpup(const __be16 *p)
 {
 	return (__force __u16)*p;
 }
-#define __cpu_to_le64s(x) __swab64s((x))
-#define __le64_to_cpus(x) __swab64s((x))
-#define __cpu_to_le32s(x) __swab32s((x))
-#define __le32_to_cpus(x) __swab32s((x))
-#define __cpu_to_le16s(x) __swab16s((x))
-#define __le16_to_cpus(x) __swab16s((x))
-#define __cpu_to_be64s(x) do {} while (0)
-#define __be64_to_cpus(x) do {} while (0)
-#define __cpu_to_be32s(x) do {} while (0)
-#define __be32_to_cpus(x) do {} while (0)
-#define __cpu_to_be16s(x) do {} while (0)
-#define __be16_to_cpus(x) do {} while (0)
+
+static inline void __cpu_to_le64s(__u64 *p)
+{
+	__swab64s(x);
+}
+
+static inline void __le64_to_cpus(__u64 *p)
+{
+	__swab64s(x);
+}
+
+static inline void __cpu_to_le32s(__u32 *p)
+{
+	__swab32s(x);
+}
+
+static inline void __le32_to_cpus(__u32 *p)
+{
+	__swab32s(x);
+}
+
+static inline void __cpu_to_le16s(__u16 *p)
+{
+	__swab16s(x);
+}
+
+static inline void __le16_to_cpus(__u16 *p)
+{
+	__swab16s(x);
+}
+
+static inline void __cpu_to_be64s(__u64 *p)
+{}
+
+static inline void __be64_to_cpus(__u64 *p)
+{}
+
+static inline void __cpu_to_be32s(__u32 *p)
+{}
+
+static inline void __be32_to_cpus(__u32 *p)
+{}
+
+static inline void __cpu_to_be16s(__u16 *p)
+{}
+
+static inline void __be16_to_cpus(__u16 *p)
+{}
 
 #ifdef __KERNEL__
 #include <linux/byteorder/generic.h>
diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
index 05dc7c3..5d12ff8 100644
--- a/include/linux/byteorder/little_endian.h
+++ b/include/linux/byteorder/little_endian.h
@@ -88,18 +88,54 @@ static inline __u16 __be16_to_cpup(const __be16 *p)
 {
 	return __swab16p((__u16 *)p);
 }
-#define __cpu_to_le64s(x) do {} while (0)
-#define __le64_to_cpus(x) do {} while (0)
-#define __cpu_to_le32s(x) do {} while (0)
-#define __le32_to_cpus(x) do {} while (0)
-#define __cpu_to_le16s(x) do {} while (0)
-#define __le16_to_cpus(x) do {} while (0)
-#define __cpu_to_be64s(x) __swab64s((x))
-#define __be64_to_cpus(x) __swab64s((x))
-#define __cpu_to_be32s(x) __swab32s((x))
-#define __be32_to_cpus(x) __swab32s((x))
-#define __cpu_to_be16s(x) __swab16s((x))
-#define __be16_to_cpus(x) __swab16s((x))
+
+static inline void __cpu_to_le64s(__u64 *p)
+{}
+
+static inline void __le64_to_cpus(__u64 *p)
+{}
+
+static inline void __cpu_to_le32s(__u32 *p)
+{}
+
+static inline void __le32_to_cpus(__u32 *p)
+{}
+
+static inline void __cpu_to_le16s(__u16 *p)
+{}
+
+static inline void __le16_to_cpus(__u16 *p)
+{}
+
+static inline void __cpu_to_be64s(__u64 *p)
+{
+	__swab64s(x);
+}
+
+static inline void __be64_to_cpus(__u64 *p)
+{
+	__swab64s(x);
+}
+
+static inline void __cpu_to_be32s(__u32 *p)
+{
+	__swab32s(x);
+}
+
+static inline void __be32_to_cpus(__u32 *p)
+{
+	__swab32s(x);
+}
+
+static inline void __cpu_to_be16s(__u16 *p)
+{
+	__swab16s(x);
+}
+
+static inline void __be16_to_cpus(__u16 *p)
+{
+	__swab16s(x);
+}
 
 #ifdef __KERNEL__
 #include <linux/byteorder/generic.h>
-- 
1.5.6.4.570.g052e




             reply	other threads:[~2008-07-25 16:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-25 16:33 Harvey Harrison [this message]
2008-07-25 18:14 ` [PATCH] byteorder: force in-place endian conversion to always evaluate args H. Peter Anvin
2008-07-25 18:19   ` Harvey Harrison
2008-07-25 18:58     ` H. Peter Anvin
2008-07-25 18:22 ` Nish Aravamudan
2008-07-25 18:25   ` Harvey Harrison
2008-07-26  5:34 ` Christoph Hellwig
2008-07-26 17:46   ` Harvey Harrison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1217003621.5971.4.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox