diff options
author | Danilo Krummrich <dakr@kernel.org> | 2025-04-14 15:18:04 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-04-19 10:41:28 +0200 |
commit | 9647b6c5095aa54701df009a7335d07013cd13c4 (patch) | |
tree | 9484ebf60ed710ca9f7724f4df3ff59fae05f831 /rust/kernel | |
parent | a38dfd60fe53a46a93517f02a061bb34c47946dc (diff) |
rust: types: add `Opaque::zeroed`
Analogous to `Opaque::uninit` add `Opaque::zeroed`, which sets the
corresponding memory to zero. In contrast to `Opaque::uninit`, the
corresponding value, depending on its type, may be initialized.
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250414131934.28418-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/types.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 9d0471afc964..eee387727d1a 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -329,6 +329,14 @@ impl<T> Opaque<T> { } } + /// Creates a new zeroed opaque value. + pub const fn zeroed() -> Self { + Self { + value: UnsafeCell::new(MaybeUninit::zeroed()), + _pin: PhantomPinned, + } + } + /// Create an opaque pin-initializer from the given pin-initializer. pub fn pin_init(slot: impl PinInit<T>) -> impl PinInit<Self> { Self::ffi_init(|ptr: *mut T| { |