samples/damon: fix damon sample wsse for start failure
authorHonggyu Kim <honggyu.kim@sk.com>
Wed, 2 Jul 2025 00:02:02 +0000 (09:02 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 04:07:55 +0000 (21:07 -0700)
The damon_sample_wsse_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 wsse because damon sample start failed but the "enable" stays as Y.

Link: https://lkml.kernel.org/r/20250702000205.1921-3-honggyu.kim@sk.com
Fixes: b757c6cfc696 ("samples/damon/wsse: start and stop DAMON as the user requests")
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/wsse.c

index 11be25803274450162e5cab7e37c8f0f07f4e003..e20238a249e7b5bf2b50de4f8b2ca21d28da57e9 100644 (file)
@@ -102,8 +102,12 @@ static int damon_sample_wsse_enable_store(
        if (enable == enabled)
                return 0;
 
-       if (enable)
-               return damon_sample_wsse_start();
+       if (enable) {
+               err = damon_sample_wsse_start();
+               if (err)
+                       enable = false;
+               return err;
+       }
        damon_sample_wsse_stop();
        return 0;
 }