Skip to content

Commit 00d5b9d

Browse files
committed
Revert "rust: lockdep: Remove support for dynamically allocated LockClassKeys"
This reverts commit 25c9b0c. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 5e6d3d8 commit 00d5b9d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

rust/kernel/sync.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,28 @@ pub struct LockClassKey(Opaque<bindings::lock_class_key>);
3030
unsafe impl Sync for LockClassKey {}
3131

3232
impl LockClassKey {
33+
/// Creates a new lock class key.
34+
pub const fn new() -> Self {
35+
Self(Opaque::uninit())
36+
}
37+
3338
pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
3439
self.0.get()
3540
}
3641
}
3742

43+
impl Default for LockClassKey {
44+
fn default() -> Self {
45+
Self::new()
46+
}
47+
}
48+
3849
/// Defines a new static lock class and returns a pointer to it.
3950
#[doc(hidden)]
4051
#[macro_export]
4152
macro_rules! static_lock_class {
4253
() => {{
43-
static CLASS: $crate::sync::LockClassKey =
44-
// SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated
45-
// lock_class_key
46-
unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
54+
static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new();
4755
&CLASS
4856
}};
4957
}

0 commit comments

Comments
 (0)