[PATCH v4 1/5] rust: types: add `Opaque::zeroed`

Danilo Krummrich posted 5 patches 8 months, 1 week ago
[PATCH v4 1/5] rust: types: add `Opaque::zeroed`
Posted by Danilo Krummrich 8 months, 1 week ago
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>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/types.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

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 @@ pub const fn uninit() -> Self {
         }
     }
 
+    /// 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| {
-- 
2.49.0
Re: [PATCH v4 1/5] rust: types: add `Opaque::zeroed`
Posted by Alice Ryhl 8 months ago
On Mon, Apr 14, 2025 at 03:18:04PM +0200, Danilo Krummrich wrote:
> 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>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Re: [PATCH v4 1/5] rust: types: add `Opaque::zeroed`
Posted by Danilo Krummrich 8 months ago
On Tue, Apr 15, 2025 at 11:59:25AM +0000, Alice Ryhl wrote:
> On Mon, Apr 14, 2025 at 03:18:04PM +0200, Danilo Krummrich wrote:
> > 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>
> > Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>

@Miguel: Can I get an ACK for taking this one through the nova tree?
Re: [PATCH v4 1/5] rust: types: add `Opaque::zeroed`
Posted by Miguel Ojeda 8 months ago
On Tue, Apr 15, 2025 at 2:44 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> @Miguel: Can I get an ACK for taking this one through the nova tree?

Sure, please go ahead.

Acked-by: Miguel Ojeda <ojeda@kernel.org>

Thanks!

Cheers,
Miguel