1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
6 #define LOG_CATEGORY LOGC_BOOT
12 #include <linux/zstd.h>
14 int zstd_decompress(struct abuf *in, struct abuf *out)
16 ZSTD_DStream *dstream;
18 ZSTD_outBuffer out_buf;
23 wsize = ZSTD_DStreamWorkspaceBound(abuf_size(in));
24 workspace = malloc(wsize);
26 debug("%s: cannot allocate workspace of size %zu\n", __func__,
31 dstream = ZSTD_initDStream(abuf_size(in), workspace, wsize);
33 log_err("%s: ZSTD_initDStream failed\n", __func__);
38 in_buf.src = abuf_data(in);
40 in_buf.size = abuf_size(in);
42 out_buf.dst = abuf_data(out);
44 out_buf.size = abuf_size(out);
49 res = ZSTD_decompressStream(dstream, &out_buf, &in_buf);
50 if (ZSTD_isError(res)) {
51 ret = ZSTD_getErrorCode(res);
52 log_err("ZSTD_decompressStream error %d\n", ret);
56 if (in_buf.pos >= abuf_size(in) || !res)