aboutsummaryrefslogtreecommitdiffstats
path: root/rust/helpers/mutex.c
diff options
context:
space:
mode:
authorLyude Paul <[email protected]>2024-11-25 20:40:58 +0000
committerBoqun Feng <[email protected]>2024-12-19 22:04:42 +0000
commitfbd7a5a0359bc770e898d918d84977ea61163aad (patch)
tree9436b34aee7d055c6952513b01a7200db0d975c1 /rust/helpers/mutex.c
parentrust: sync: Add SpinLockGuard type alias (diff)
downloadkernel-fbd7a5a0359bc770e898d918d84977ea61163aad.tar.gz
kernel-fbd7a5a0359bc770e898d918d84977ea61163aad.zip
rust: sync: Add lock::Backend::assert_is_held()
Since we've exposed Lock::from_raw() and Guard::new() publically, we want to be able to make sure that we assert that a lock is actually held when constructing a Guard for it to handle instances of unsafe Guard::new() calls outside of our lock module. Hence add a new method assert_is_held() to Backend, which uses lockdep to check whether or not a lock has been acquired. When lockdep is disabled, this has no overhead. [Boqun: Resolve the conflicts with exposing Guard::new(), reword the commit log a bit and format "unsafe { <statement>; }" into "unsafe { <statement> }" for the consistency. ] Signed-off-by: Lyude Paul <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'rust/helpers/mutex.c')
-rw-r--r--rust/helpers/mutex.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/rust/helpers/mutex.c b/rust/helpers/mutex.c
index 7e00680958ef..06575553eda5 100644
--- a/rust/helpers/mutex.c
+++ b/rust/helpers/mutex.c
@@ -12,3 +12,8 @@ void rust_helper___mutex_init(struct mutex *mutex, const char *name,
{
__mutex_init(mutex, name, key);
}
+
+void rust_helper_mutex_assert_is_held(struct mutex *mutex)
+{
+ lockdep_assert_held(mutex);
+}