From: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
To: sj@kernel.org, akpm@linux-foundation.org
Cc: shu17az@gmail.com, jiayuan.chen@shopee.com,
jaeyeon.lee.dev@gmail.com, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm/damon/tests: use scoped_guard() for damon_test_ops_registration
Date: Sat, 15 Aug 2026 16:30:39 +0200 [thread overview]
Message-ID: <20260815143039.17291-1-jaeyeon.lee.dev@gmail.com> (raw)
Replace manual mutex_lock() and mutex_unlock() calls with the
scoped_guard() macro. This simplifies the code, improves readability,
and ensures that the lock is automatically released when the scope
ends, preventing potential lock leaks in the future.
Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
---
mm/damon/tests/core-kunit.h | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 4a536d41cdb2..770927a30021 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -434,17 +434,17 @@ static void damon_test_ops_registration(struct kunit *test)
KUNIT_EXPECT_EQ(test, damon_select_ops(c, NR_DAMON_OPS), -EINVAL);
/* Registration should success after unregistration */
- mutex_lock(&damon_ops_lock);
- bak = damon_registered_ops[DAMON_OPS_VADDR];
- damon_registered_ops[DAMON_OPS_VADDR] = (struct damon_operations){};
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock) {
+ bak = damon_registered_ops[DAMON_OPS_VADDR];
+ damon_registered_ops[DAMON_OPS_VADDR] =
+ (struct damon_operations){};
+ }
ops.id = DAMON_OPS_VADDR;
KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), 0);
- mutex_lock(&damon_ops_lock);
- damon_registered_ops[DAMON_OPS_VADDR] = bak;
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock)
+ damon_registered_ops[DAMON_OPS_VADDR] = bak;
/* Check double-registration failure again */
KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
@@ -452,10 +452,9 @@ static void damon_test_ops_registration(struct kunit *test)
damon_destroy_ctx(c);
if (need_cleanup) {
- mutex_lock(&damon_ops_lock);
- damon_registered_ops[DAMON_OPS_VADDR] =
- (struct damon_operations){};
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock)
+ damon_registered_ops[DAMON_OPS_VADDR] =
+ (struct damon_operations){};
}
}
--
2.43.0
next reply other threads:[~2026-08-15 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 14:30 Jaeyeon Lee [this message]
2026-08-15 15:30 ` [PATCH] mm/damon/tests: use scoped_guard() for damon_test_ops_registration SJ Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260815143039.17291-1-jaeyeon.lee.dev@gmail.com \
--to=jaeyeon.lee.dev@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shu17az@gmail.com \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox