[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ec3adfb8-006d-4778-ba4a-e9222461e38d@gmail.com>
Date: Fri, 30 May 2025 18:18:07 +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 3/7] rust: devres: support fallible in-place init for data
On 30.05.25 4:24 PM, Danilo Krummrich wrote:
> Currently, Devres only supports a data argument of type T. However,
> DevresInner already uses pin-init to initialize the Revocable. Hence,
> there is no need for this limitation and we can take a data argument of
> type impl PinInit<T, E> instead.
>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
Reviewed-by: Christian Schrefl <chrisi.schrefl@...il.com>
> rust/kernel/devres.rs | 27 ++++++++++++++++++++++-----
> 1 file changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
> index 2dbe17d6ea1f..47aeb5196dd2 100644
> --- a/rust/kernel/devres.rs
> +++ b/rust/kernel/devres.rs
> @@ -96,9 +96,16 @@ struct DevresInner<T> {
> pub struct Devres<T>(Arc<DevresInner<T>>);
>
> impl<T> DevresInner<T> {
> - fn new(dev: &Device<Bound>, data: T, flags: Flags) -> Result<Arc<DevresInner<T>>> {
> - let inner = Arc::pin_init(
> - try_pin_init!( DevresInner {
> + fn new<E>(
> + dev: &Device<Bound>,
> + data: impl PinInit<T, E>,
> + flags: Flags,
> + ) -> Result<Arc<DevresInner<T>>>
> + where
> + Error: From<E>,
> + {
> + let inner = Arc::pin_init::<Error>(
> + try_pin_init!( Self {
> dev: dev.into(),
> callback: Self::devres_callback,
> data <- Revocable::new(data),
> @@ -168,7 +175,10 @@ fn remove_action(this: &Arc<Self>) {
> impl<T> Devres<T> {
> /// Creates a new [`Devres`] instance of the given `data`. The `data` encapsulated within the
> /// returned `Devres` instance' `data` will be revoked once the device is detached.
> - pub fn new(dev: &Device<Bound>, data: T, flags: Flags) -> Result<Self> {
> + pub fn new<E>(dev: &Device<Bound>, data: impl PinInit<T, E>, flags: Flags) -> Result<Self>
> + where
> + Error: From<E>,
> + {
> let inner = DevresInner::new(dev, data, flags)?;
>
> Ok(Devres(inner))
> @@ -176,7 +186,14 @@ pub fn new(dev: &Device<Bound>, data: T, flags: Flags) -> Result<Self> {
>
> /// Same as [`Devres::new`], but does not return a `Devres` instance. Instead the given `data`
> /// is owned by devres and will be revoked / dropped, once the device is detached.
> - pub fn new_foreign_owned(dev: &Device<Bound>, data: T, flags: Flags) -> Result {
> + pub fn new_foreign_owned<E>(
> + dev: &Device<Bound>,
> + data: impl PinInit<T, E>,
> + flags: Flags,
> + ) -> Result
> + where
> + Error: From<E>,
> + {
> let _ = DevresInner::new(dev, data, flags)?;
>
> Ok(())
Powered by blists - more mailing lists