1 // SPDX-License-Identifier: GPL-2.0+
2 #include "decompress.h"
4 #if IS_ENABLED(CONFIG_LZ4)
5 #include <u-boot/lz4.h>
6 static int z_erofs_decompress_lz4(struct z_erofs_decompress_req *rq)
12 bool support_0padding = false;
13 unsigned int inputmargin = 0;
15 if (erofs_sb_has_lz4_0padding()) {
16 support_0padding = true;
18 while (!src[inputmargin & ~PAGE_MASK])
19 if (!(++inputmargin & ~PAGE_MASK))
22 if (inputmargin >= rq->inputsize)
26 if (rq->decodedskip) {
27 buff = malloc(rq->decodedlength);
33 if (rq->partial_decoding || !support_0padding)
34 ret = LZ4_decompress_safe_partial(src + inputmargin, dest,
35 rq->inputsize - inputmargin,
36 rq->decodedlength, rq->decodedlength);
38 ret = LZ4_decompress_safe(src + inputmargin, dest,
39 rq->inputsize - inputmargin,
42 if (ret != (int)rq->decodedlength) {
48 memcpy(rq->out, dest + rq->decodedskip,
49 rq->decodedlength - rq->decodedskip);
59 int z_erofs_decompress(struct z_erofs_decompress_req *rq)
61 if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED) {
62 if (rq->inputsize != EROFS_BLKSIZ)
65 DBG_BUGON(rq->decodedlength > EROFS_BLKSIZ);
66 DBG_BUGON(rq->decodedlength < rq->decodedskip);
68 memcpy(rq->out, rq->in + rq->decodedskip,
69 rq->decodedlength - rq->decodedskip);
73 #if IS_ENABLED(CONFIG_LZ4)
74 if (rq->alg == Z_EROFS_COMPRESSION_LZ4)
75 return z_erofs_decompress_lz4(rq);