Linux block layer
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Haoqin Huang <haoqinhuang7@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>,
	 Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jens Axboe <axboe@kernel.dk>, Nick Terrell <terrelln@fb.com>,
	 David Sterba <dsterba@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	 Haoqin Huang <haoqinhuang@tencent.com>,
	Rongwei Wang <zigiwang@tencent.com>
Subject: Re: [PATCH v2 4/5] zram: add per-backend caps and validate parameters early
Date: Wed, 29 Jul 2026 11:26:22 +0900	[thread overview]
Message-ID: <amljgWJnBBJtZ6jQ@google.com> (raw)
In-Reply-To: <20260728092935.31139-4-haoqinhuang7@gmail.com>

On (26/07/28 17:29), Haoqin Huang wrote:
[..]
> +unsigned int zcomp_get_caps(const char *comp)
> +{
> +	const struct zcomp_ops *backend = lookup_backend_ops(comp);
> +
> +	return backend ? backend->caps : 0;
> +}
> +
> +int zcomp_validate_level(const char *comp, s32 level)
> +{
> +	const struct zcomp_ops *backend = lookup_backend_ops(comp);
> +
> +	if (!backend)
> +		return -EINVAL;
> +	if (!(backend->caps & ZCOMP_CAP_LEVEL))
> +		return -EOPNOTSUPP;
> +	if (level < backend->level_min || level > backend->level_max)
> +		return -EINVAL;
> +	return 0;
> +}

[..]

> +unsigned int zcomp_get_caps(const char *comp);
> +int zcomp_validate_level(const char *comp, s32 level);

[..]

> @@ -1796,6 +1796,25 @@ static ssize_t algorithm_params_store(struct device *dev,
>  			return -EINVAL;
>  	}
>  
> +	if (zram->comp_algs[prio]) {
> +		unsigned int caps = zcomp_get_caps(zram->comp_algs[prio]);
> +
> +		if (dict_path && !(caps & ZCOMP_CAP_DICT)) {
> +			pr_err("zram: %s does not support dictionary\n",
> +			       zram->comp_algs[prio]);
> +			return -EOPNOTSUPP;
> +		}
> +
> +		if (level != ZCOMP_PARAM_NOT_SET) {
> +			ret = zcomp_validate_level(zram->comp_algs[prio], level);
> +			if (ret) {
> +				pr_err("zram: invalid level for %s\n",
> +				       zram->comp_algs[prio]);
> +				return ret;
> +			}
> +		}
> +	}

So I wonder if instead of introducing 2 new zcomp functions (zcomp_get_caps()
and zcomp_validate_level()) and still basically open-coding params verification
in zram, maybe we we can just have one
	int zcomp_validate_params(comp, level, dict_path)
and handle all the validation in zcomp internally.  So that in
algorithm_params_store() it will be just

	ret = zcomp_validate_params(zram->comp_algs[prio], level, dict_path);
	if (ret)
		return ret;

  reply	other threads:[~2026-07-29  2:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27  7:02 [PATCH 1/3] zram: fix zstd dict use-after-free on per-CPU error path Haoqin Huang
2026-06-27  7:02 ` [PATCH 2/3] zram: add per-backend capability flags and validate parameters early Haoqin Huang
2026-07-24  5:27   ` Sergey Senozhatsky
2026-07-27 16:50     ` haoqin huang
2026-07-28  1:19       ` Sergey Senozhatsky
2026-07-28  9:07         ` haoqin huang
2026-07-28  1:27   ` Sergey Senozhatsky
2026-07-28  9:09     ` haoqin huang
2026-06-27  7:02 ` [PATCH 3/3] zram: reset per-priority params when changing algorithm before init Haoqin Huang
2026-07-24  5:19   ` Sergey Senozhatsky
2026-07-07  7:19 ` [PATCH 1/3] zram: fix zstd dict use-after-free on per-CPU error path Sergey Senozhatsky
2026-07-24  5:17 ` Sergey Senozhatsky
2026-07-27 16:06   ` haoqin huang
2026-07-28  1:21     ` Sergey Senozhatsky
2026-07-28  9:29 ` [PATCH v2 1/5] zram: fix early release of global cdict/ddict in " Haoqin Huang
2026-07-28  9:29   ` [PATCH v2 2/5] zram: make dict update in comp_params_store() atomic Haoqin Huang
2026-07-29  2:30     ` Sergey Senozhatsky
2026-07-29  4:06       ` haoqin huang
2026-07-29  4:16         ` Sergey Senozhatsky
2026-07-29  4:25           ` haoqin huang
2026-07-28  9:29   ` [PATCH v2 3/5] zstd: move ZSTD_MAX_CLEVEL to zstd_lib.h Haoqin Huang
2026-07-29  3:03     ` Sergey Senozhatsky
2026-07-29  4:16       ` haoqin huang
2026-07-29  4:22         ` Sergey Senozhatsky
2026-07-29  4:32           ` haoqin huang
2026-07-29  4:49             ` Sergey Senozhatsky
2026-07-28  9:29   ` [PATCH v2 4/5] zram: add per-backend caps and validate parameters early Haoqin Huang
2026-07-29  2:26     ` Sergey Senozhatsky [this message]
2026-07-29  3:53       ` haoqin huang
2026-07-28  9:29   ` [PATCH v2 5/5] zram: reset per-priority params when changing algorithm before init Haoqin Huang
2026-07-29  0:34   ` [PATCH v2 1/5] zram: fix early release of global cdict/ddict in per-CPU error path Andrew Morton
2026-07-29  2:49     ` Sergey Senozhatsky
2026-07-29  3:33     ` haoqin huang
2026-07-29  2:20   ` Sergey Senozhatsky
2026-07-29  3:40     ` haoqin huang
2026-07-29  2:40   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=amljgWJnBBJtZ6jQ@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=dsterba@suse.com \
    --cc=haoqinhuang7@gmail.com \
    --cc=haoqinhuang@tencent.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=terrelln@fb.com \
    --cc=zigiwang@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox