Skip to content

Commit a507f82

Browse files
ritvikosvireshk
authored andcommitted
rust: cpumask: Replace MaybeUninit and mem::zeroed with Opaque APIs
Replace the following unsafe initializations: 1. `MaybeUninit::uninit().assume_init()` with `Opaque::uninit()` 2. `core::mem::zeroed()` with `Opaque::zeroed()` Suggested-by: Benno Lossin <lossin@kernel.org> Link: Rust-for-Linux#1178 Suggested-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/rust-for-linux/CAH5fLgj0OoCn56OkNUmiPQ=RAVa_VmS-yMZ4TNBSpGPNtZ5D0A@mail.gmail.com/ Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Ritvik Gupta <ritvikfoss@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 0ae9338 commit a507f82

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

rust/kernel/cpumask.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use crate::{
1414
#[cfg(CONFIG_CPUMASK_OFFSTACK)]
1515
use core::ptr::{self, NonNull};
1616

17-
#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
18-
use core::mem::MaybeUninit;
19-
2017
use core::ops::{Deref, DerefMut};
2118

2219
/// A CPU Mask.
@@ -239,10 +236,7 @@ impl CpumaskVar {
239236
},
240237

241238
#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
242-
// SAFETY: FFI type is valid to be zero-initialized.
243-
//
244-
// INVARIANT: The associated memory is freed when the `CpumaskVar` goes out of scope.
245-
mask: unsafe { core::mem::zeroed() },
239+
mask: Cpumask(Opaque::zeroed()),
246240
})
247241
}
248242

@@ -266,10 +260,7 @@ impl CpumaskVar {
266260
NonNull::new(ptr.cast()).ok_or(AllocError)?
267261
},
268262
#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
269-
// SAFETY: Guaranteed by the safety requirements of the function.
270-
//
271-
// INVARIANT: The associated memory is freed when the `CpumaskVar` goes out of scope.
272-
mask: unsafe { MaybeUninit::uninit().assume_init() },
263+
mask: Cpumask(Opaque::uninit()),
273264
})
274265
}
275266

0 commit comments

Comments
 (0)