samples/damon: fix damon sample mtier for start failure
authorHonggyu Kim <honggyu.kim@sk.com>
Wed, 2 Jul 2025 00:02:03 +0000 (09:02 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 04:07:55 +0000 (21:07 -0700)
The damon_sample_mtier_start() can fail so we must reset the "enable"
parameter to "false" again for proper rollback.

In such cases, setting Y to "enable" then N triggers the similar crash
with mtier because damon sample start failed but the "enable" stays as Y.

Link: https://lkml.kernel.org/r/20250702000205.1921-4-honggyu.kim@sk.com
Fixes: 82a08bde3cf7 ("samples/damon: implement a DAMON module for memory tiering")
Signed-off-by: Honggyu Kim <honggyu.kim@sk.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
samples/damon/mtier.c

index 36d2cd933f5a6f03a400093fb796ffcdd62606bc..c94254b77fc98422d646315f4a6d880971a41fd3 100644 (file)
@@ -164,8 +164,12 @@ static int damon_sample_mtier_enable_store(
        if (enable == enabled)
                return 0;
 
-       if (enable)
-               return damon_sample_mtier_start();
+       if (enable) {
+               err = damon_sample_mtier_start();
+               if (err)
+                       enable = false;
+               return err;
+       }
        damon_sample_mtier_stop();
        return 0;
 }