From: Lin Liu <lin....@citrix.com>

These wrappers simply hide a deference, which adds to the cognitive complexity
of reading the code.  As such, they're not going to be included in the new
byteswap infrastructure.

No functional change.

Signed-off-by: Lin Liu <lin....@citrix.com>
Signed-off-by: Andrew Cooper <andrew.coop...@citrix.com>
---
CC: Anthony PERARD <anthony.per...@vates.tech>
CC: Michal Orzel <michal.or...@amd.com>
CC: Jan Beulich <jbeul...@suse.com>
CC: Julien Grall <jul...@xen.org>
CC: Roger Pau Monné <roger....@citrix.com>
CC: Stefano Stabellini <sstabell...@kernel.org>
CC: Volodymyr Babchuk <volodymyr_babc...@epam.com>
CC: Bertrand Marquis <bertrand.marq...@arm.com>
CC: Shawn Anastasio <sanasta...@raptorengineering.com>
CC: Oleksii Kurochko <oleksii.kuroc...@gmail.com>
CC: Daniel P. Smith <dpsm...@apertussolutions.com>
CC: Lin Liu <lin....@citrix.com>

v5:
 * Rebase
 * Rearranged from other patches
---
 tools/libs/guest/xg_dom_decompress_unsafe_xz.c | 13 +++++++------
 xen/common/lz4/defs.h                          |  6 +++++-
 xen/common/xz/private.h                        | 12 +++++++++---
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c 
b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
index 80eed912dd68..7dbd2622c3b8 100644
--- a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
+++ b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
@@ -19,18 +19,19 @@ typedef uint32_t __le32;
 static inline u32 cpu_to_le32(const u32 v)
 {
 #if BYTE_ORDER == BIG_ENDIAN
-       return (((v & 0x000000ffUL) << 24) |
-               ((v & 0x0000ff00UL) <<  8) |
-               ((v & 0x00ff0000UL) >>  8) |
-               ((v & 0xff000000UL) >> 24));
+        return __builtin_bswap32(v);
 #else
        return v;
 #endif
 }
 
-static inline u32 le32_to_cpup(const u32 *p)
+static inline u32 le32_to_cpu(const u32 p)
 {
-       return cpu_to_le32(*p);
+#if BYTE_ORDER == BIG_ENDIAN
+        return __builtin_bswap32(v);
+#else
+       return v;
+#endif
 }
 
 #define __force
diff --git a/xen/common/lz4/defs.h b/xen/common/lz4/defs.h
index ecfbf07f8323..e477806634c1 100644
--- a/xen/common/lz4/defs.h
+++ b/xen/common/lz4/defs.h
@@ -18,7 +18,11 @@
 
 static inline u16 get_unaligned_le16(const void *p)
 {
-       return le16_to_cpup(p);
+       u16 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le16_to_cpu(v);
 }
 
 #endif
diff --git a/xen/common/xz/private.h b/xen/common/xz/private.h
index 2299705378ac..a63379994fd6 100644
--- a/xen/common/xz/private.h
+++ b/xen/common/xz/private.h
@@ -18,17 +18,23 @@
 
 static inline u32 get_unaligned_le32(const void *p)
 {
-       return le32_to_cpup(p);
+       u32 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le32_to_cpu(v);
 }
 
 static inline void put_unaligned_le32(u32 val, void *p)
 {
-       *(__force __le32*)p = cpu_to_le32(val);
+       u32 v = cpu_to_le32(val);
+
+       memcpy(p, &v, sizeof(v));
 }
 
 #endif
 
-#define get_le32(p) le32_to_cpup((const uint32_t *)(p))
+#define get_le32(p) le32_to_cpu(*(const uint32_t *)(p))
 
 #define false 0
 #define true 1
-- 
2.39.5


Reply via email to