]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: revocable: support fallible PinInit types
authorDanilo Krummrich <dakr@kernel.org>
Thu, 26 Jun 2025 20:00:39 +0000 (22:00 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Sat, 28 Jun 2025 16:06:52 +0000 (18:06 +0200)
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.

Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250626200054.243480-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/devres.rs
rust/kernel/revocable.rs

index 8ede607414fd58c23c5a4a156f7dfd25853989be..fd8b75aa03bc95d81060b18a61ee8958750bbe17 100644 (file)
@@ -100,7 +100,7 @@ pub struct Devres<T: Send>(Arc<DevresInner<T>>);
 impl<T: Send> 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),
index fa1fd70efa27190e24c92ad54a5affbbfb61b7cc..46768b3746566b6cf365c09b6e811331aec3ae2e 100644 (file)
@@ -82,11 +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, E> {
+        try_pin_init!(Self {
             is_available: AtomicBool::new(true),
             data <- Opaque::pin_init(data),
-        })
+        }? E)
     }
 
     /// Tries to access the revocable wrapped object.