Skip to contentSkip to conversation

rust: cpumask: Replace `MaybeUninit` with `Opaque::uninit`

PATCH In review Ritvik Gupta 3 participants 3 messages Jul 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: cpumask: Replace `MaybeUninit` with `Opaque::uninit`

Replace unsafe MaybeUninit::uninit().assume_init() initialization with Opaque::uninit(), which is an abstraction for handling opaque FFI types.

---
 rust/kernel/cpumask.rs | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
rust/kernel/cpumask.rs +1 -7
index 4bce230a73b68..5f84b8797c2a7 100644
@@ -14,9 +14,6 @@
 #[cfg(CONFIG_CPUMASK_OFFSTACK)]
 use core::ptr::{self, NonNull};
 
-#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
-use core::mem::MaybeUninit;
-
 use core::ops::{Deref, DerefMut};
 
 /// A CPU Mask.
@@ -266,10 +263,7 @@ pub unsafe fn new(_flags: Flags) -> Result<Self, AllocError> {
                 NonNull::new(ptr.cast()).ok_or(AllocError)?
             },
             #[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
-            // SAFETY: Guaranteed by the safety requirements of the function.
-            //
-            // INVARIANT: The associated memory is freed when the `CpumaskVar` goes out of scope.
-            mask: unsafe { MaybeUninit::uninit().assume_init() },
+            mask: Cpumask(Opaque::uninit()),
         })
     }
 

base-commit: 2009a2d5696944d85c34d75e691a6f3884e787c0

Signature · 1 line
2.50.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ritvik Gupta

Replace unsafe MaybeUninit::uninit().assume_init() initialization with Opaque::uninit(), which is an abstraction for handling opaque FFI types.

I would make the same change to the mem::zeroed() call in CpumaskVar::new_zeroed().

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Ritvik Gupta
Quoted 5 lines · Ritvik Gupta

Replace unsafe MaybeUninit::uninit().assume_init() initialization with Opaque::uninit(), which is an abstraction for handling opaque FFI types.

@Viresh when you take this, please use <[email protected]> :)

(it also is in .mailmap, so maybe it will automatically be fixed?)

Quoted 2 lines

Thanks!

---
Cheers,
Benno

Quoted 3 lines
---
 rust/kernel/cpumask.rs | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)