RE: [PATCH] zram: compression algorithms name use static fields

From: gao xu

Date: Thu Feb 26 2026 - 06:51:49 EST


>
> On (26/02/26 07:50), gao xu wrote:
> [..]
> > @@ -1648,6 +1644,7 @@ static int __comp_algorithm_store(struct zram
> *zram, u32 prio, const char *buf)
> > {
> > char *compressor;
> > size_t sz;
> > + const char *alg;
> >
> > sz = strlen(buf);
> > if (sz >= ZRAM_MAX_ALGO_NAME_SZ)
> > @@ -1661,10 +1658,10 @@ static int __comp_algorithm_store(struct zram
> *zram, u32 prio, const char *buf)
> > if (sz > 0 && compressor[sz - 1] == '\n')
> > compressor[sz - 1] = 0x00;
> >
> > - if (!zcomp_available_algorithm(compressor)) {
> > - kfree(compressor);
> > + alg = zcomp_lookup_backend_name(compressor);
> > + kfree(compressor);
>
> I guess we don't really need to kstrdup() the compressor name? Lookup
> uses sysfs_streq(), which should take care of terminating \n, so I assume
> we can just pass `buf` to zcomp_lookup_backend_name() directly?
>
> I guess we also can get rid of `[sz - 1] == '\n'` thing?
I've verified your suggested changes and haven't found any issues.
I will incorporate this modification into the v2 version.