|
6 | 6 | //! modules, including lock classes. |
7 | 7 |
|
8 | 8 | use crate::{ |
| 9 | + alloc::{box_ext::BoxExt, flags::*, vec_ext::VecExt}, |
9 | 10 | c_str, fmt, |
10 | 11 | init::InPlaceInit, |
11 | 12 | new_mutex, |
@@ -123,7 +124,7 @@ fn caller_lock_class_inner() -> Result<&'static DynLockClassKey> { |
123 | 124 |
|
124 | 125 | let mut ptr = slot.load(Ordering::Relaxed); |
125 | 126 | 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)?; |
127 | 128 |
|
128 | 129 | // SAFETY: We never move out of this Box |
129 | 130 | let raw = Box::into_raw(unsafe { Pin::into_inner_unchecked(new_element) }); |
@@ -156,17 +157,20 @@ fn caller_lock_class_inner() -> Result<&'static DynLockClassKey> { |
156 | 157 | } |
157 | 158 |
|
158 | 159 | // 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 | + )?); |
164 | 168 |
|
165 | 169 | // SAFETY: This is safe to call with a pointer to a dynamically allocated lockdep key, |
166 | 170 | // and we never free the objects so it is safe to never unregister the key. |
167 | 171 | unsafe { bindings::lockdep_register_key(new_class.key.get()) }; |
168 | 172 |
|
169 | | - guard.try_push(new_class)?; |
| 173 | + guard.push(new_class, GFP_KERNEL)?; |
170 | 174 |
|
171 | 175 | Ok(new_class) |
172 | 176 | } |
|
0 commit comments