]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
samples/damon/mtier: use damon_initialized()
authorSeongJae Park <sj@kernel.org>
Tue, 16 Sep 2025 03:35:11 +0000 (20:35 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Sep 2025 21:22:39 +0000 (14:22 -0700)
damon_sample_mtier is assuming DAMON is ready to use in module_init time,
and uses its own hack to see if it is the time.  Use damon_initialized(),
which is a way for seeing if DAMON is ready to be used that is more
reliable and better to maintain instead of the hack.

Link: https://lkml.kernel.org/r/20250916033511.116366-8-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
samples/damon/mtier.c

index beaf36657deacc21bd74486c2c8107eacb329870..775838a23d935366a12ea8adb925bf39eb0f9778 100644 (file)
@@ -193,8 +193,6 @@ static void damon_sample_mtier_stop(void)
        damon_destroy_ctx(ctxs[1]);
 }
 
-static bool init_called;
-
 static int damon_sample_mtier_enable_store(
                const char *val, const struct kernel_param *kp)
 {
@@ -208,7 +206,7 @@ static int damon_sample_mtier_enable_store(
        if (enabled == is_enabled)
                return 0;
 
-       if (!init_called)
+       if (!damon_initialized())
                return 0;
 
        if (enabled) {
@@ -225,7 +223,12 @@ static int __init damon_sample_mtier_init(void)
 {
        int err = 0;
 
-       init_called = true;
+       if (!damon_initialized()) {
+               if (enabled)
+                       enabled = false;
+               return -ENOMEM;
+       }
+
        if (enabled) {
                err = damon_sample_mtier_start();
                if (err)