45 lines
1.1 KiB
Diff
45 lines
1.1 KiB
Diff
diff --git a/crypto/zstd.c b/crypto/zstd.c
|
|
--- a/crypto/zstd.c
|
|
+++ b/crypto/zstd.c
|
|
@@ -96,6 +96,7 @@ static int zstd_compress_one(struct acomp_req *req, struct zstd_ctx *ctx,
|
|
|
|
static int zstd_compress(struct acomp_req *req)
|
|
{
|
|
+ bool stream_initialized = false;
|
|
struct crypto_acomp_stream *s;
|
|
unsigned int pos, scur, dcur;
|
|
unsigned int total_out = 0;
|
|
@@ -115,12 +116,6 @@ static int zstd_compress(struct acomp_req *req)
|
|
if (ret)
|
|
goto out;
|
|
|
|
- ctx->cctx = zstd_init_cstream(&ctx->params, 0, ctx->wksp, ctx->wksp_size);
|
|
- if (!ctx->cctx) {
|
|
- ret = -EINVAL;
|
|
- goto out;
|
|
- }
|
|
-
|
|
do {
|
|
dcur = acomp_walk_next_dst(&walk);
|
|
if (!dcur) {
|
|
@@ -142,6 +137,19 @@ static int zstd_compress(struct acomp_req *req)
|
|
goto out;
|
|
}
|
|
|
|
+ if (!stream_initialized) {
|
|
+ ctx->cctx = zstd_init_cstream(&ctx->params, 0,
|
|
+ ctx->wksp, ctx->wksp_size);
|
|
+ if (!ctx->cctx) {
|
|
+ /* Release in the reverse of the map order. */
|
|
+ acomp_walk_done_src(&walk, 0);
|
|
+ acomp_walk_done_dst(&walk, 0);
|
|
+ ret = -EINVAL;
|
|
+ goto out;
|
|
+ }
|
|
+ stream_initialized = true;
|
|
+ }
|
|
+
|
|
if (scur) {
|
|
inbuf.pos = 0;
|
|
inbuf.src = walk.src.virt.addr;
|