[RFC PATCH v1.1 01/11] mm/damon/core: stop ctxs in damon_start() before returning an error

From: SJ Park

Date: Sun Jul 05 2026 - 12:02:08 EST


When multiple contexts are passed to damon_start(), the function starts
the contexts one by one. If any of the operations fails, it immediately
returns an error. Contexts that successfully started before the failure
keep running. The caller should catch this and stop the contexts. It
is complicated and easy to make mistakes. Stop all contexts in
damon_start() under the failures.

Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3c5a46e1c079a..d89a7f2faf350 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1917,6 +1917,9 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive)
running_exclusive_ctxs = true;
mutex_unlock(&damon_lock);

+ if (i != nr_ctxs)
+ damon_stop(ctxs, i);
+
return err;
}

--
2.47.3