[PATCH 3/4] zram: reject unrecognized type= values in recompress_store()
From: Andrew Stellman
Date: Tue Apr 07 2026 - 08:40:07 EST
recompress_store() parses the type= parameter with three independent 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.
Convert the if chain to if/else if/else and return -EINVAL for
unrecognized values, consistent with the function's other parameter
validation.
Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
drivers/block/zram/zram_drv.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
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
@@ -2555,10 +2555,12 @@ static ssize_t recompress_store(struct device *dev,
if (!strcmp(param, "type")) {
if (!strcmp(val, "idle"))
mode = RECOMPRESS_IDLE;
- if (!strcmp(val, "huge"))
+ else if (!strcmp(val, "huge"))
mode = RECOMPRESS_HUGE;
- if (!strcmp(val, "huge_idle"))
+ else if (!strcmp(val, "huge_idle"))
mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE;
+ else
+ return -EINVAL;
continue;
}
--
2.34.1