dm vdo: use kernel byteswapping routines instead of GCC ones
Subsystems (2)
Matthew Sakai
maintainerPATCH 1/1 dm vdo: use kernel byteswapping routines instead of GCC ones
From: Ken Raeburn <[email protected]>
--- drivers/md/dm-vdo/murmurhash3.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/md/dm-vdo/murmurhash3.c +4 -14
@@ -8,6 +8,8 @@#include "murmurhash3.h" +#include <asm/byteorder.h> +static inline u64 rotl64 (u64 x,s8 r) {return (x << r) | (x >> (64 - r));
@@ -16,24 +18,12 @@ static inline u64 rotl64(u64 x, s8 r)#define ROTL64 (x, y) rotl64(x, y) static __always_inline u64 getblock64(const u64 *p, int i) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -return p[i]; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -return __builtin_bswap64 (p[i]); -#else -#error "can't figure out byte order" -#endif +return le64_to_cpup (&p[i]); } static __always_inline void putblock64(u64 *p, int i, u64 value) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - p[i] = value; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - p[i] =__builtin_bswap64 (value); -#else -#error "can't figure out byte order" -#endif + p[i] =cpu_to_le64 (value); }/* Finalization mix - force all bits of a hash block to avalanche */
Signature · 1 line
2.42.0
Quoted 5 lines · Matthew Sakai
From: Ken Raeburn <[email protected]>
Reported-by Guenter Roeck <[email protected]>Signed-off-by Ken Raeburn <[email protected]>Signed-off-by Matthew Sakai <[email protected]>
Quoted 47 lines
--- drivers/md/dm-vdo/murmurhash3.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)drivers/md/dm-vdo/murmurhash3.c +4
-14@@ -8,6 +8,8 @@#include "murmurhash3.h" +#include <asm/byteorder.h> +static inline u64 rotl64 (u64 x,s8 r) {return (x << r) | (x >> (64 - r));@@ -16,24 +18,12 @@ static inline u64 rotl64(u64 x, s8 r)#define ROTL64 (x, y) rotl64(x, y) static __always_inline u64 getblock64(const u64 *p, int i) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -return p[i]; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -return __builtin_bswap64 (p[i]); -#else -#error "can't figure out byte order" -#endif +return le64_to_cpup (&p[i]); } static __always_inline void putblock64(u64 *p, int i, u64 value) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - p[i] = value; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - p[i] =__builtin_bswap64 (value); -#else -#error "can't figure out byte order" -#endif + p[i] =cpu_to_le64 (value); }/* Finalization mix - force all bits of a hash block to avalanche */ Signature · 1 line
2.42.0
Quoted 13 lines · Matthew Sakai
static
__always_inlineu64getblock64(const u64 *p, int i){drivers/md/dm-vdo/murmurhash3.c +1
-7-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -return p[i]; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -return __builtin_bswap64 (p[i]); -#else -#error "can't figure out byte order" -#endif +return le64_to_cpup (&p[i]); } static __always_inline void putblock64(u64 *p, int i, u64 value)
drivers/md/dm-vdo/murmurhash3.c static inline u64 rotl64(u64 x, s8 r) · line 27
Quoted 10 lines
drivers/md/dm-vdo/murmurhash3.c +1
-7{ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - p[i] = value; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - p[i] =__builtin_bswap64 (value); -#else -#error "can't figure out byte order" -#endif + p[i] =cpu_to_le64 (value); }
This is very broken. What you're actually looking for is get_unaligned_le64() and put_unaligned_le64(). And they should be folded directly into the caller.
- Eric
Matthew Sakai
maintainerQuoted 28 lines · Eric Biggers
Quoted 13 lines · Matthew Sakai
static __always_inline u64 getblock64(const u64 *p, int i) {drivers/md/dm-vdo/murmurhash3.c +1
-7-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -return p[i]; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -return __builtin_bswap64 (p[i]); -#else -#error "can't figure out byte order" -#endif +return le64_to_cpup (&p[i]); } static __always_inline void putblock64(u64 *p, int i, u64 value)drivers/md/dm-vdo/murmurhash3.c static inline u64 rotl64(u64 x, s8 r) · line 27
Quoted 10 lines
drivers/md/dm-vdo/murmurhash3.c +1
-7{ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - p[i] = value; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - p[i] =__builtin_bswap64 (value); -#else -#error "can't figure out byte order" -#endif + p[i] =cpu_to_le64 (value); }This is very broken. What you're actually looking for is
get_unaligned_le64()andput_unaligned_le64(). And they should be folded directly into the caller.
Quoted 2 lines
- Eric
Thanks for the suggestion. We'll work on a v2 to include this.
Matt