[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DAKO8MMSCUE4.1WVR6SBADGP8W@kernel.org>
Date: Thu, 12 Jun 2025 17:48:36 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Danilo Krummrich" <dakr@...nel.org>, <gregkh@...uxfoundation.org>,
<rafael@...nel.org>, <ojeda@...nel.org>, <alex.gaynor@...il.com>,
<boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
<benno.lossin@...ton.me>, <a.hindborg@...nel.org>, <aliceryhl@...gle.com>,
<tmgross@...ch.edu>
Cc: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/4] rust: revocable: support fallible PinInit types
On Thu Jun 12, 2025 at 4:51 PM CEST, Danilo Krummrich wrote:
> Currently, Revocable::new() only supports infallible PinInit
> implementations, i.e. impl PinInit<T, Infallible>.
>
> This has been sufficient so far, since users such as Devres do not
> support fallibility.
>
> Since this is about to change, make Revocable::new() generic over the
> error type E.
>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
> rust/kernel/devres.rs | 2 +-
> rust/kernel/revocable.rs | 7 +++++--
> 2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
> index d8bdf2bdb879..a7df9fbd724f 100644
> --- a/rust/kernel/devres.rs
> +++ b/rust/kernel/devres.rs
> @@ -98,7 +98,7 @@ struct DevresInner<T> {
> impl<T> DevresInner<T> {
> fn new(dev: &Device<Bound>, data: T, flags: Flags) -> Result<Arc<DevresInner<T>>> {
> let inner = Arc::pin_init(
> - pin_init!( DevresInner {
> + try_pin_init!( DevresInner {
> dev: dev.into(),
> callback: Self::devres_callback,
> data <- Revocable::new(data),
> diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
> index fa1fd70efa27..41b8fe374af6 100644
> --- a/rust/kernel/revocable.rs
> +++ b/rust/kernel/revocable.rs
> @@ -82,8 +82,11 @@ unsafe impl<T: Sync + Send> Sync for Revocable<T> {}
>
> impl<T> Revocable<T> {
> /// Creates a new revocable instance of the given data.
> - pub fn new(data: impl PinInit<T>) -> impl PinInit<Self> {
> - pin_init!(Self {
> + pub fn new<E>(data: impl PinInit<T, E>) -> impl PinInit<Self, Error>
> + where
> + Error: From<E>,
I don't think we need this bound as you don't use it in the function
body.
---
Cheers,
Benno
> + {
> + try_pin_init!(Self {
> is_available: AtomicBool::new(true),
> data <- Opaque::pin_init(data),
> })
Powered by blists - more mailing lists