return backends[i];
}
-bool zcomp_available_algorithm(const char *comp)
+const char *zcomp_lookup_backend_name(const char *comp)
{
- return lookup_backend_ops(comp) != NULL;
+ const struct zcomp_ops *backend = lookup_backend_ops(comp);
+
+ if (backend)
+ return backend->name;
+
+ return NULL;
}
/* show available compressors */
int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node);
int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
ssize_t zcomp_available_show(const char *comp, char *buf, ssize_t at);
-bool zcomp_available_algorithm(const char *comp);
+const char *zcomp_lookup_backend_name(const char *comp);
struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params);
void zcomp_destroy(struct zcomp *comp);
static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg)
{
- /* Do not free statically defined compression algorithms */
- if (zram->comp_algs[prio] != default_compressor)
- kfree(zram->comp_algs[prio]);
-
zram->comp_algs[prio] = alg;
}
static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
{
- char *compressor;
+ const char *alg;
size_t sz;
sz = strlen(buf);
if (sz >= ZRAM_MAX_ALGO_NAME_SZ)
return -E2BIG;
- compressor = kstrdup(buf, GFP_KERNEL);
- if (!compressor)
- return -ENOMEM;
-
- /* ignore trailing newline */
- if (sz > 0 && compressor[sz - 1] == '\n')
- compressor[sz - 1] = 0x00;
-
- if (!zcomp_available_algorithm(compressor)) {
- kfree(compressor);
+ alg = zcomp_lookup_backend_name(buf);
+ if (!alg)
return -EINVAL;
- }
guard(rwsem_write)(&zram->dev_lock);
if (init_done(zram)) {
- kfree(compressor);
pr_info("Can't change algorithm for initialized device\n");
return -EBUSY;
}
- comp_algorithm_set(zram, prio, compressor);
+ comp_algorithm_set(zram, prio, alg);
return 0;
}
zram->num_active_comps--;
}
- for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
- /* Do not free statically defined compression algorithms */
- if (zram->comp_algs[prio] != default_compressor)
- kfree(zram->comp_algs[prio]);
+ for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++)
zram->comp_algs[prio] = NULL;
- }
zram_comp_params_reset(zram);
}