Re: [PATCH v3 4/5] zram: add per-backend caps and validate parameters early

haoqin huang <[email protected]> Thu, 30 Jul 2026 13:57:38 +0800
Newsgroups org.kernel.vger.linux-block,org.kernel.vger.linux-kernel
Message-ID <CAEjiKSmgvA+6PzRA-u3by99bP7mJrkRb+=Er1Qt1j=mAsBRzGg@mail.gmail.com>
On Thu, Jul 30, 2026 at 11:14 AM Sergey Senozhatsky
<[email protected]> wrote:
>
> On (26/07/30 10:52), Haoqin Huang wrote:
> [..]
> > +int zcomp_validate_params(const char *comp, s32 level, const char *dict_path)
> > +{
> > +     const struct zcomp_ops *backend = lookup_backend_ops(comp);
> > +
> > +     if (!backend)
> > +             return -EINVAL;
> > +
> > +     if (dict_path && !(backend->caps & ZCOMP_CAP_DICT)) {
> > +             pr_err("zram: %s does not support dictionary\n", comp);
> > +             return -EOPNOTSUPP;
> > +     }
> > +
> > +     if (level != ZCOMP_PARAM_NOT_SET) {
> > +             if (!(backend->caps & ZCOMP_CAP_LEVEL)) {
> > +                     pr_err("zram: %s does not support level\n", comp);
> > +                     return -EOPNOTSUPP;
> > +             }
> > +             /* level_max == -1 means validate in .setup_params() */
> > +             if (backend->level_max >= 0 &&
> > +                 (level < backend->level_min || level > backend->level_max)) {
> > +                     pr_err("zram: invalid level %d for %s\n", level, comp);
> > +                     return -EINVAL;
> > +             }
> > +     }
> > +     return 0;
> > +}
>
> I was thinking that you'd move all params validation to backend's
> .setup_params(), not just zstd, but for every backend.  Sorry if
> my message was not clear.  Can we move all validation to backends?

Sorry, I misunderstood. I thought you meant only the zstd-level check.
Done in v4: all validation (dict and level) now lives in each backend's
.setup_params(), no caps or zcomp_validate_params() needed.