summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-09-25 07:03:10 -0600
committerTom Rini <trini@konsulko.com>2021-10-08 15:53:26 -0400
commit918adf8e07337719750c57be0939824247973b1e (patch)
tree0397283ede32ce80e759336eb6c6dec3d4e7c449 /fs
parent94d0a2efc0315e2c5e3b62a7420292f0ce058079 (diff)
downloadu-boot-918adf8e07337719750c57be0939824247973b1e.tar.gz
btrfs: Use U-Boot API for decompression
Use the common function to avoid code duplication. Acked-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/compression.c51
1 files changed, 5 insertions, 46 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 23efefa199..7adfbb04a7 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -6,6 +6,7 @@
*/
#include "btrfs.h"
+#include <abuf.h>
#include <log.h>
#include <malloc.h>
#include <linux/lzo.h>
@@ -136,54 +137,12 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 *dbuf, u32 dlen)
static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
{
- ZSTD_DStream *dstream;
- ZSTD_inBuffer in_buf;
- ZSTD_outBuffer out_buf;
- void *workspace;
- size_t wsize;
- u32 res = -1;
-
- wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT);
- workspace = malloc(wsize);
- if (!workspace) {
- debug("%s: cannot allocate workspace of size %zu\n", __func__,
- wsize);
- return -1;
- }
-
- dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize);
- if (!dstream) {
- printf("%s: ZSTD_initDStream failed\n", __func__);
- goto err_free;
- }
+ struct abuf in, out;
- in_buf.src = cbuf;
- in_buf.pos = 0;
- in_buf.size = clen;
+ abuf_init_set(&in, (u8 *)cbuf, clen);
+ abuf_init_set(&out, dbuf, dlen);
- out_buf.dst = dbuf;
- out_buf.pos = 0;
- out_buf.size = dlen;
-
- while (1) {
- size_t ret;
-
- ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf);
- if (ZSTD_isError(ret)) {
- printf("%s: ZSTD_decompressStream error %d\n", __func__,
- ZSTD_getErrorCode(ret));
- goto err_free;
- }
-
- if (in_buf.pos >= clen || !ret)
- break;
- }
-
- res = out_buf.pos;
-
-err_free:
- free(workspace);
- return res;
+ return zstd_decompress(&in, &out);
}
u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen)