[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d30be54d-f2dd-4394-b677-193cb2d77f1c@gmail.com>
Date: Fri, 30 May 2025 18:15:35 +0200
From: Christian Schrefl <chrisi.schrefl@...il.com>
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 2/7] rust: revocable: support fallible PinInit types
On 30.05.25 4:24 PM, 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>
> ---
Reviewed-by: Christian Schrefl <chrisi.schrefl@...il.com>
> 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 0f79a2ec9474..2dbe17d6ea1f 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 db4aa46bb121..ca738f75dc10 100644
> --- a/rust/kernel/revocable.rs
> +++ b/rust/kernel/revocable.rs
> @@ -80,8 +80,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>,
> + {
> + try_pin_init!(Self {
> is_available: AtomicBool::new(true),
> data <- Opaque::pin_init(data),
> })
Powered by blists - more mailing lists