From b9943b9604de6c07fb391e9b1ec6d0a67ae30d69 Mon Sep 17 00:00:00 2001 From: SeongJae Park Date: Fri, 19 Nov 2021 16:43:52 -0800 Subject: [PATCH] BACKPORT: mm/damon/dbgfs: fix missed use of damon_dbgfs_lock DAMON debugfs is supposed to protect dbgfs_ctxs, dbgfs_nr_ctxs, and dbgfs_dirs using damon_dbgfs_lock. However, some of the code is accessing the variables without the protection. This fixes it by protecting all such accesses. Link: https://lkml.kernel.org/r/20211110145758.16558-3-sj@kernel.org Fixes: 75c1c2b53c78 ("mm/damon/dbgfs: support multiple contexts") Signed-off-by: SeongJae Park Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit d78f3853f831eee46c6dbe726debf3be9e9c0d05) Bug: 228223814 Signed-off-by: zhijun wan Change-Id: Ibdfcc75f9f219b69a4b4e6161af257c1d0eba891 --- mm/damon/dbgfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index afb4e9ebc842..3181692d34d2 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -894,6 +894,7 @@ static ssize_t dbgfs_monitor_on_write(struct file *file, for (i = 0; i < dbgfs_nr_ctxs; i++) { if (damon_targets_empty(dbgfs_ctxs[i])) { kfree(kbuf); + mutex_unlock(&damon_dbgfs_lock); return -EINVAL; } }