Skip to content

Commit 5f4476e

Browse files
author
Danilo Krummrich
committed
rust: auxiliary: add Driver::unbind() callback
Add missing unbind() callback to auxiliary::Driver, since it will be needed by drivers eventually (e.g. the Nova DRM driver). Acked-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260107103511.570525-3-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 4181ace commit 5f4476e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

rust/kernel/auxiliary.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ impl<T: Driver + 'static> Adapter<T> {
8787
// SAFETY: `remove_callback` is only ever called after a successful call to
8888
// `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called
8989
// and stored a `Pin<KBox<T>>`.
90-
drop(unsafe { adev.as_ref().drvdata_obtain::<T>() });
90+
let data = unsafe { adev.as_ref().drvdata_obtain::<T>() };
91+
92+
T::unbind(adev, data.as_ref());
9193
}
9294
}
9395

@@ -187,6 +189,20 @@ pub trait Driver {
187189
///
188190
/// Called when an auxiliary device is matches a corresponding driver.
189191
fn probe(dev: &Device<device::Core>, id_info: &Self::IdInfo) -> impl PinInit<Self, Error>;
192+
193+
/// Auxiliary driver unbind.
194+
///
195+
/// Called when a [`Device`] is unbound from its bound [`Driver`]. Implementing this callback
196+
/// is optional.
197+
///
198+
/// This callback serves as a place for drivers to perform teardown operations that require a
199+
/// `&Device<Core>` or `&Device<Bound>` reference. For instance, drivers may try to perform I/O
200+
/// operations to gracefully tear down the device.
201+
///
202+
/// Otherwise, release operations for driver resources should be performed in `Self::drop`.
203+
fn unbind(dev: &Device<device::Core>, this: Pin<&Self>) {
204+
let _ = (dev, this);
205+
}
190206
}
191207

192208
/// The auxiliary device representation.

0 commit comments

Comments
 (0)