zram: do not release zstd global params from error paths

Patch series "zram: fix zstd error paths and add parameter validation", v6,

Patch 1 removes zstd_release_params() from both zstd_create() and
zstd_setup_params() error paths -- the former is a layering violation
in a per-CPU callback, the latter is redundant as zcomp_init() already
calls release_params() on setup failure.

Patch 2 rejects zero-size dictionaries and prints distinct error
messages for sz < 0 (returns the original error code) and sz == 0
("empty file"). Currently errors are silently swallowed.

Patch 3 adds pr_fmt to each backend file so that pr_err() messages
are auto-prefixed with the algorithm name.

Patch 4 validates dict and level parameters in each backend's
.setup_params(), rejecting unsupported combinations and out-of-range
levels.

Patch 5 resets per-priority params on algorithm change before init.


This patch (of 5):

zstd_setup_params() creates global cdict and ddict stored in
params->drv_data, shared across all per-CPU contexts.  The per-CPU
zstd_create() error path called zstd_release_params(), which freed those
globally-shared objects.  This is a layering violation: a per-CPU callback
should only clean up its own context, not release resources owned by the
compression lifecycle.

zstd_setup_params() called zstd_release_params() on its own error path as
well, but zcomp_init() already calls release_params() when setup fails, so
this is redundant.

Remove zstd_release_params() from both error paths.

Link: https://lore.kernel.org/20260804093841.67920-1-haoqinhuang7@gmail.com
Link: https://lore.kernel.org/20260804093841.67920-2-haoqinhuang7@gmail.com
Signed-off-by: Haoqin Huang <haoqinhuang@tencent.com>
Signed-off-by: Rongwei Wang <zigiwang@tencent.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Tested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: David Sterba <dsterba@suse.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Haoqin Huang 2026-08-04 17:38:37 +08:00 committed by Andrew Morton
parent 0ddb8bb85b
commit 45214458d6

View File

@ -85,7 +85,6 @@ static int zstd_setup_params(struct zcomp_params *params)
return 0;
error:
zstd_release_params(params);
return -EINVAL;
}
@ -161,7 +160,6 @@ static int zstd_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
return 0;
error:
zstd_release_params(params);
zstd_destroy(ctx);
return -EINVAL;
}