[PATCH v2] zram: reject unrecognized type= values in recompress_store()
From: Andrew Stellman
Date: Tue Apr 07 2026 - 11:33:47 EST
recompress_store() parses the type= parameter with three if statements
checking for "idle", "huge", and "huge_idle". An unrecognized value
silently falls through with mode left at 0, causing the recompression
pass to run with no slot filter — processing all slots instead of the
intended subset.
Add a !mode check after the type parsing block to return -EINVAL for
unrecognized values, consistent with the function's other parameter
validation.
Suggested-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
- Use !mode check after the strcmp chain instead of restructuring
into if/else if/else, as suggested by Sergey Senozhatsky.
drivers/block/zram/zram_drv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8ea2a12..67dea80 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2552,6 +2552,9 @@ static ssize_t recompress_store(struct device *dev,
if (!strcmp(val, "huge_idle"))
mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE;
+ if (!mode)
+ return -EINVAL;
+
continue;
}
--
2.34.1