[for-1.4,1/2] bswap: Fix width of swap in leul_to_cpu

Message ID 1360023667-7712-1-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson Feb. 5, 2013, 12:21 a.m.
The misnamed HOST_LONG_BITS is really HOST_POINTER_BITS.  Here we're
explicitly using an unsigned long, rather than uintptr_t, so it is
more correct to select the swap size via ULONG_MAX.

Acked-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Richard Henderson <rth@twiddle.net>
 include/qemu/bswap.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

This is one of many patches around that fixes the build on big-endian
hosts.  And indeed is not the only one that should be applied, as there
are arguably several bugs involved.



Anthony Liguori Feb. 6, 2013, 8:41 p.m. | #1
Applied.  Thanks.


Anthony Liguori


diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index e6d4798..d3af35d 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -2,8 +2,8 @@ 
 #define BSWAP_H
 #include "config-host.h"
 #include <inttypes.h>
+#include <limits.h>
 #include "fpu/softfloat.h"
@@ -458,7 +458,15 @@  static inline void cpu_to_32wu(uint32_t *p, uint32_t v)
 static inline unsigned long leul_to_cpu(unsigned long v)
-    return le_bswap(v, HOST_LONG_BITS);
+    /* In order to break an include loop between here and
+       qemu-common.h, don't rely on HOST_LONG_BITS.  */
+    return le_bswap(v, 32);
+#elif ULONG_MAX == UINT64_MAX
+    return le_bswap(v, 64);
+# error Unknown sizeof long
 #undef le_bswap