[PATCH 4/4] zram: add init_done() guard to algorithm_params_store()

From: Andrew Stellman

Date: Tue Apr 07 2026 - 08:40:41 EST


algorithm_params_store() allows writing compression parameters after
the zram device has been initialized. Peer sysfs store functions
(comp_algorithm_store, disksize_store, mem_limit_store) all check
init_done(zram) and return -EBUSY when the device is already in use.
algorithm_params_store() uniquely lacks this guard, allowing runtime
mutation of compression parameters on an active device.

Acquire dev_lock and check init_done() immediately before calling
comp_params_store(), after argument parsing and priority resolution
complete. This keeps the lock scope narrow and matches the pattern in
__comp_algorithm_store().

Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
drivers/block/zram/zram_drv.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 67dea80..d270964 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1772,6 +1772,12 @@ static ssize_t algorithm_params_store(struct device *dev,
if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
return -EINVAL;

+ guard(rwsem_write)(&zram->dev_lock);
+ if (init_done(zram)) {
+ pr_info("Can't change algorithm params for initialized device\n");
+ return -EBUSY;
+ }
+
ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
return ret ? ret : len;
}
--
2.34.1