| // SPDX-License-Identifier: GPL-2.0+ |
| * Copyright 2021 Google LLC |
| #define LOG_CATEGORY LOGC_BOOT |
| int zstd_decompress(struct abuf *in, struct abuf *out) |
| wsize = zstd_dctx_workspace_bound(); |
| workspace = malloc(wsize); |
| debug("%s: cannot allocate workspace of size %zu\n", __func__, |
| ctx = zstd_init_dctx(workspace, wsize); |
| log_err("%s: zstd_init_dctx() failed\n", __func__); |
| * Find out how large the frame actually is, there may be junk at |
| * the end of the frame that zstd_decompress_dctx() can't handle. |
| len = zstd_find_frame_compressed_size(abuf_data(in), abuf_size(in)); |
| if (zstd_is_error(len)) { |
| log_err("%s: failed to detect compressed size: %d\n", __func__, |
| zstd_get_error_code(len)); |
| len = zstd_decompress_dctx(ctx, abuf_data(out), abuf_size(out), |
| if (zstd_is_error(len)) { |
| log_err("%s: failed to decompress: %d\n", __func__, |
| zstd_get_error_code(len)); |