[PATCH 1/2] mm/damon/reclaim: reject non-power-of-2 addr_unit
From: Josh Law
Date: Thu Mar 19 2026 - 12:28:40 EST
DAMON_MIN_REGION_SZ / addr_unit is used as min_region_sz, which is
passed to ALIGN() and ALIGN_DOWN() in core.c. These macros require
power-of-2 alignment. When addr_unit is not a power of 2 (e.g., 3),
the division produces a non-power-of-2 min_region_sz, causing silent
undefined behavior in ALIGN before damon_commit_ctx() gets a chance
to reject it.
Validate that addr_unit is a power of 2 in the store function so the
user gets immediate -EINVAL feedback instead of a silent failure.
Signed-off-by: Josh Law <objecting@xxxxxxxxxxxxx>
---
mm/damon/reclaim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 43d76f5bed44..9b55df304e51 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -321,7 +321,7 @@ static int damon_reclaim_addr_unit_store(const char *val,
if (err)
return err;
- if (!input_addr_unit)
+ if (!input_addr_unit || !is_power_of_2(input_addr_unit))
return -EINVAL;
addr_unit = input_addr_unit;
--
2.34.1