Skip to content

Commit dd7fdee

Browse files
committed
fixup! rust: sync: Implement dynamic lockdep class creation
Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 40ba7e6 commit dd7fdee

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

rust/kernel/sync/lockdep.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! modules, including lock classes.
77
88
use crate::{
9+
alloc::{box_ext::BoxExt, flags::*, vec_ext::VecExt},
910
c_str, fmt,
1011
init::InPlaceInit,
1112
new_mutex,
@@ -123,7 +124,7 @@ fn caller_lock_class_inner() -> Result<&'static DynLockClassKey> {
123124

124125
let mut ptr = slot.load(Ordering::Relaxed);
125126
if ptr.is_null() {
126-
let new_element = Box::pin_init(new_mutex!(Vec::new()))?;
127+
let new_element = Box::pin_init(new_mutex!(Vec::new()), GFP_KERNEL)?;
127128

128129
// SAFETY: We never move out of this Box
129130
let raw = Box::into_raw(unsafe { Pin::into_inner_unchecked(new_element) });
@@ -156,17 +157,20 @@ fn caller_lock_class_inner() -> Result<&'static DynLockClassKey> {
156157
}
157158

158159
// We immediately leak the class, so it becomes 'static
159-
let new_class = Box::leak(Box::try_new(DynLockClassKey {
160-
key: Opaque::zeroed(),
161-
loc: loc_key,
162-
name: CString::try_from_fmt(fmt!("{}:{}:{}", loc.file(), loc.line(), loc.column()))?,
163-
})?);
160+
let new_class = Box::leak(Box::new(
161+
DynLockClassKey {
162+
key: Opaque::zeroed(),
163+
loc: loc_key,
164+
name: CString::try_from_fmt(fmt!("{}:{}:{}", loc.file(), loc.line(), loc.column()))?,
165+
},
166+
GFP_KERNEL,
167+
)?);
164168

165169
// SAFETY: This is safe to call with a pointer to a dynamically allocated lockdep key,
166170
// and we never free the objects so it is safe to never unregister the key.
167171
unsafe { bindings::lockdep_register_key(new_class.key.get()) };
168172

169-
guard.try_push(new_class)?;
173+
guard.push(new_class, GFP_KERNEL)?;
170174

171175
Ok(new_class)
172176
}

0 commit comments

Comments
 (0)