Skip to content

Commit

Permalink
include/linux/lz4.h: add some missing macros
Browse files Browse the repository at this point in the history
Currently, LZ4_DISTANCE_MAX and LZ4_DECOMPRESS_INPLACE_MARGIN are
defined in the erofs subsystem for LZ4 in-place decompression, which is
somewhat unsuitable since they should belong to the LZ4 itself and
may change with future LZ4 codebase updates.

Move them to include/linux/lz4.h to match the upstream LZ4 library [1].
No logic changes.

[1] https://github.com/lz4/lz4/blob/v1.10.0/lib/lz4.h#L670

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Gao Xiang <[email protected]>
Cc: Yann Collet <[email protected]>
Cc: Nick Terrell <[email protected]>
Cc: Chao Yu <[email protected]>
Cc: Yue Hu <[email protected]>
Cc; Jeffle Xu <[email protected]>
Cc: Sandeep Dhavale <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
hsiangkao authored and akpm00 committed Jan 25, 2025
1 parent 13fd5cf commit f0ef073
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
7 changes: 0 additions & 7 deletions fs/erofs/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
#include "compress.h"
#include <linux/lz4.h>

#ifndef LZ4_DISTANCE_MAX /* history window size */
#define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
#endif

#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1)
#ifndef LZ4_DECOMPRESS_INPLACE_MARGIN
#define LZ4_DECOMPRESS_INPLACE_MARGIN(srcsize) (((srcsize) >> 8) + 32)
#endif

struct z_erofs_lz4_decompress_ctx {
struct z_erofs_decompress_req *rq;
Expand Down
6 changes: 6 additions & 0 deletions include/linux/lz4.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,10 @@ int LZ4_decompress_safe_usingDict(const char *source, char *dest,
int LZ4_decompress_fast_usingDict(const char *source, char *dest,
int originalSize, const char *dictStart, int dictSize);

#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)

#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
#define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
#endif

#endif
1 change: 0 additions & 1 deletion lib/lz4/lz4_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
/*-************************************
* Dependencies
**************************************/
#include <linux/lz4.h>
#include "lz4defs.h"
#include <linux/module.h>
#include <linux/kernel.h>
Expand Down
1 change: 0 additions & 1 deletion lib/lz4/lz4_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
/*-************************************
* Dependencies
**************************************/
#include <linux/lz4.h>
#include "lz4defs.h"
#include <linux/init.h>
#include <linux/module.h>
Expand Down
4 changes: 2 additions & 2 deletions lib/lz4/lz4defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <linux/bitops.h>
#include <linux/string.h> /* memset, memcpy */
#include <linux/lz4.h>

#define FORCE_INLINE __always_inline

Expand Down Expand Up @@ -92,8 +93,7 @@ typedef uintptr_t uptrval;
#define MB (1 << 20)
#define GB (1U << 30)

#define MAXD_LOG 16
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
#define MAX_DISTANCE LZ4_DISTANCE_MAX
#define STEPSIZE sizeof(size_t)

#define ML_BITS 4
Expand Down
1 change: 0 additions & 1 deletion lib/lz4/lz4hc_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
/*-************************************
* Dependencies
**************************************/
#include <linux/lz4.h>
#include "lz4defs.h"
#include <linux/module.h>
#include <linux/kernel.h>
Expand Down

0 comments on commit f0ef073

Please sign in to comment.