[PATCH 1/7] zram: allocate comp only if it is supported
From: Sergey Senozhatsky
Date: Tue Dec 01 2026 - 04:07:23 EST
Currently comp allocation happens before zram checks if
requested algorithm is even supported. Defer comp
allocation.
Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
---
drivers/block/zram/zcomp.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index d05f3cbe6d9d..adf6d368ae6c 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -506,6 +506,7 @@ void zcomp_destroy(struct zcomp *comp)
struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params,
bool recomp)
{
+ const struct zcomp_ops *ops;
struct zcomp *comp;
int error;
@@ -517,16 +518,15 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params,
*/
BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
+ ops = lookup_backend_ops(alg);
+ if (!ops)
+ return ERR_PTR(-EINVAL);
+
comp = kzalloc_obj(struct zcomp);
if (!comp)
return ERR_PTR(-ENOMEM);
- comp->ops = lookup_backend_ops(alg);
- if (!comp->ops) {
- kfree(comp);
- return ERR_PTR(-EINVAL);
- }
-
+ comp->ops = ops;
error = zcomp_init(comp, params, recomp);
if (error) {
kfree(comp);
--
2.56.1.839.g22a8290db9-goog