Skip to content

Commit

Permalink
lib: lz4: fixed zram with lz4 on big endian machines
Browse files Browse the repository at this point in the history
Based on Sergey's test patch [1], this fixes zram with lz4 compression
on big endian cpus.

Note that the 64-bit preprocessor test is not a cleanup, it's part of
the fix, since those identifiers are bogus (for example, __ppc64__
isn't defined anywhere else in the kernel, which means we'd fall into
the 32-bit definitions on ppc64).

Tested on ppc64 with no regression on x86_64.

[1] http://marc.info/?l=linux-kernel&m=145994470805853&w=4

Cc: [email protected]
Suggested-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Rui Salvaterra <[email protected]>
Reviewed-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rsalvaterra authored and gregkh committed Apr 13, 2016
1 parent 87243de commit 3e26a69
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/lz4/lz4defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
/*
* Detects 64 bits mode
*/
#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) \
|| defined(__ppc64__) || defined(__LP64__))
#if defined(CONFIG_64BIT)
#define LZ4_ARCH64 1
#else
#define LZ4_ARCH64 0
Expand All @@ -35,6 +34,10 @@ typedef struct _U64_S { u64 v; } U64_S;

#define PUT4(s, d) (A32(d) = A32(s))
#define PUT8(s, d) (A64(d) = A64(s))

#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
(d = s - A16(p))

#define LZ4_WRITE_LITTLEENDIAN_16(p, v) \
do { \
A16(p) = v; \
Expand All @@ -51,10 +54,13 @@ typedef struct _U64_S { u64 v; } U64_S;
#define PUT8(s, d) \
put_unaligned(get_unaligned((const u64 *) s), (u64 *) d)

#define LZ4_WRITE_LITTLEENDIAN_16(p, v) \
do { \
put_unaligned(v, (u16 *)(p)); \
p += 2; \
#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
(d = s - get_unaligned_le16(p))

#define LZ4_WRITE_LITTLEENDIAN_16(p, v) \
do { \
put_unaligned_le16(v, (u16 *)(p)); \
p += 2; \
} while (0)
#endif

Expand Down Expand Up @@ -140,9 +146,6 @@ typedef struct _U64_S { u64 v; } U64_S;

#endif

#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
(d = s - get_unaligned_le16(p))

#define LZ4_WILDCOPY(s, d, e) \
do { \
LZ4_COPYPACKET(s, d); \
Expand Down

0 comments on commit 3e26a69

Please sign in to comment.