Re: [PATCH 1/4] rust: revocable: support fallible PinInit types
From: Benno Lossin
Date: Thu Jun 12 2025 - 11:58:50 EST
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@xxxxxxxxxx>
> ---
> 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),
> })