]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/sysfs: use damon_kdamond_pid()
authorSeongJae Park <sj@kernel.org>
Thu, 15 Jan 2026 15:20:42 +0000 (07:20 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Jan 2026 04:02:37 +0000 (20:02 -0800)
DAMON sysfs interface directly uses damon_ctx->kdamond field with manual
synchronization using damon_ctx->kdamond_lock, to get the pid of the
kdamond.  Use a new dedicated function for the purpose, namely
damon_kdamond_pid(), since that doesn't require manual and error-prone
synchronization.

Avoid use of kdamond_lock outside of the core.

Link: https://lkml.kernel.org/r/20260115152047.68415-3-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs.c

index 95fd9375a7d84110b25b5f52ec723b827e6d11c8..4de25708b05a5471d7708f72f70e412130de9521 100644 (file)
@@ -1819,10 +1819,9 @@ static ssize_t pid_show(struct kobject *kobj,
        if (!ctx)
                goto out;
 
-       mutex_lock(&ctx->kdamond_lock);
-       if (ctx->kdamond)
-               pid = ctx->kdamond->pid;
-       mutex_unlock(&ctx->kdamond_lock);
+       pid = damon_kdamond_pid(ctx);
+       if (pid < 0)
+               pid = -1;
 out:
        mutex_unlock(&damon_sysfs_lock);
        return sysfs_emit(buf, "%d\n", pid);