[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241224202120.581b7088.gary@garyguo.net>
Date: Tue, 24 Dec 2024 20:21:20 +0000
From: Gary Guo <gary@...yguo.net>
To: Danilo Krummrich <dakr@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, bhelgaas@...gle.com,
ojeda@...nel.org, alex.gaynor@...il.com, boqun.feng@...il.com,
bjorn3_gh@...tonmail.com, benno.lossin@...ton.me, tmgross@...ch.edu,
a.hindborg@...sung.com, aliceryhl@...gle.com, airlied@...il.com,
fujita.tomonori@...il.com, lina@...hilina.net, pstanner@...hat.com,
ajanulgu@...hat.com, lyude@...hat.com, robh@...nel.org,
daniel.almeida@...labora.com, saravanak@...gle.com,
dirk.behme@...bosch.com, j@...nau.net, fabien.parent@...aro.org,
chrisi.schrefl@...il.com, paulmck@...nel.org,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org, devicetree@...r.kernel.org, rcu@...r.kernel.org
Subject: Re: [PATCH v7 05/16] rust: types: add `Opaque::pin_init`
On Thu, 19 Dec 2024 18:04:07 +0100
Danilo Krummrich <dakr@...nel.org> wrote:
> Analogous to `Opaque::new` add `Opaque::pin_init`, which instead of a
> value `T` takes a `PinInit<T>` and returns a `PinInit<Opaque<T>>`.
>
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> Suggested-by: Alice Ryhl <aliceryhl@...gle.com>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
Reviewed-by: Gary Guo <gary@...yguo.net>
> ---
> rust/kernel/types.rs | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
> index ec6457bb3084..3aea6af9a0bc 100644
> --- a/rust/kernel/types.rs
> +++ b/rust/kernel/types.rs
> @@ -281,6 +281,17 @@ pub const fn uninit() -> Self {
> }
> }
>
> + /// 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| {
> + // SAFETY:
> + // - `ptr` is a valid pointer to uninitialized memory,
> + // - `slot` is not accessed on error; the call is infallible,
> + // - `slot` is pinned in memory.
> + let _ = unsafe { init::PinInit::<T>::__pinned_init(slot, ptr) };
> + })
> + }
> +
> /// Creates a pin-initializer from the given initializer closure.
> ///
> /// The returned initializer calls the given closure with the pointer to the inner `T` of this
Powered by blists - more mailing lists