[PATCH v6 0/5] zram: fix zstd error paths and add parameter validation

Haoqin Huang posted 5 patches 1 month, 4 weeks ago
drivers/block/zram/backend_842.c     | 10 +++++++++
drivers/block/zram/backend_deflate.c | 17 ++++++++++++--
drivers/block/zram/backend_lz4.c     | 10 ++++++++-
drivers/block/zram/backend_lz4hc.c   | 16 +++++++++++++-
drivers/block/zram/backend_lzo.c     | 10 +++++++++
drivers/block/zram/backend_lzorle.c  | 10 +++++++++
drivers/block/zram/backend_zstd.c    | 11 +++++++---
drivers/block/zram/zram_drv.c        | 33 ++++++++++++++++++----------
8 files changed, 98 insertions(+), 19 deletions(-)
[PATCH v6 0/5] zram: fix zstd error paths and add parameter validation
Posted by Haoqin Huang 1 month, 4 weeks ago
From: Haoqin Huang <haoqinhuang@tencent.com>

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.

Changes since v5:
  - Patch 2: split pr_err into sz < 0 and sz == 0 branches
  - New patch 3: add pr_fmt to all backends; tweak winbits message;
    add missing SPDX headers to lz4 and lz4hc
  - Patch 4: removed inline algo-name prefixes (now handled by pr_fmt);
    added comment for lz4hc < 1 lower bound; added braces to if
    branches for consistency

v5: https://lore.kernel.org/all/20260803141256.60599-1-haoqinhuang7@gmail.com/

Haoqin Huang (5):
  zram: do not release zstd global params from error paths
  zram: reject zero-size dictionary
  zram: add pr_fmt to backend files
  zram: validate parameters in each backend's setup_params
  zram: reset per-priority params when changing algorithm before init

 drivers/block/zram/backend_842.c     | 10 +++++++++
 drivers/block/zram/backend_deflate.c | 17 ++++++++++++--
 drivers/block/zram/backend_lz4.c     | 10 ++++++++-
 drivers/block/zram/backend_lz4hc.c   | 16 +++++++++++++-
 drivers/block/zram/backend_lzo.c     | 10 +++++++++
 drivers/block/zram/backend_lzorle.c  | 10 +++++++++
 drivers/block/zram/backend_zstd.c    | 11 +++++++---
 drivers/block/zram/zram_drv.c        | 33 ++++++++++++++++++----------
 8 files changed, 98 insertions(+), 19 deletions(-)

-- 
2.43.7
Re: [PATCH v6 0/5] zram: fix zstd error paths and add parameter validation
Posted by Sergey Senozhatsky 1 month, 4 weeks ago
On (26/08/04 17:38), Haoqin Huang wrote:
> From: Haoqin Huang <haoqinhuang@tencent.com>
> 
> 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.
> 
> Changes since v5:
>   - Patch 2: split pr_err into sz < 0 and sz == 0 branches
>   - New patch 3: add pr_fmt to all backends; tweak winbits message;
>     add missing SPDX headers to lz4 and lz4hc
>   - Patch 4: removed inline algo-name prefixes (now handled by pr_fmt);
>     added comment for lz4hc < 1 lower bound; added braces to if
>     branches for consistency

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Re: [PATCH v6 0/5] zram: fix zstd error paths and add parameter validation
Posted by Sergey Senozhatsky 1 month, 4 weeks ago
On (26/08/04 18:53), Sergey Senozhatsky wrote:
> > 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.
> > 
> > Changes since v5:
> >   - Patch 2: split pr_err into sz < 0 and sz == 0 branches
> >   - New patch 3: add pr_fmt to all backends; tweak winbits message;
> >     add missing SPDX headers to lz4 and lz4hc
> >   - Patch 4: removed inline algo-name prefixes (now handled by pr_fmt);
> >     added comment for lz4hc < 1 lower bound; added braces to if
> >     branches for consistency
> 
> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

Oh, and also
Tested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Re: [PATCH v6 0/5] zram: fix zstd error paths and add parameter validation
Posted by Andrew Morton 1 month, 4 weeks ago
On Tue,  4 Aug 2026 17:38:36 +0800 Haoqin Huang <haoqinhuang7@gmail.com> wrote:

> 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.
> 

Thanks.  AI review pointed at a few things, most of them pre-existing:
	https://sashiko.dev/#/patchset/20260804093841.67920-1-haoqinhuang7@gmail.com