1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
6 #define LOG_CATEGORY LOGC_BOOT
11 #include <linux/errno.h>
12 #include <linux/zstd.h>
14 int zstd_decompress(struct abuf *in, struct abuf *out)
21 wsize = zstd_dctx_workspace_bound();
22 workspace = malloc(wsize);
24 debug("%s: cannot allocate workspace of size %zu\n", __func__,
29 ctx = zstd_init_dctx(workspace, wsize);
31 log_err("%s: zstd_init_dctx() failed\n", __func__);
37 * Find out how large the frame actually is, there may be junk at
38 * the end of the frame that zstd_decompress_dctx() can't handle.
40 len = zstd_find_frame_compressed_size(abuf_data(in), abuf_size(in));
41 if (zstd_is_error(len)) {
42 log_err("%s: failed to detect compressed size: %d\n", __func__,
43 zstd_get_error_code(len));
48 len = zstd_decompress_dctx(ctx, abuf_data(out), abuf_size(out),
50 if (zstd_is_error(len)) {
51 log_err("%s: failed to decompress: %d\n", __func__,
52 zstd_get_error_code(len));