[PATCH 1/7] rust: pci: remove the unbind() callback

From: Danilo Krummrich

Date: Wed Nov 11 2026 - 20:05:53 EST


The driver model uses native Rust lifetimes to let driver data retain
device resources and a Device<Bound> reference for the duration of the
binding. Both remain accessible from the destructor, so a separate
unbind() callback is no longer needed.

Remove pci::Driver::unbind() and the adapter's remove callback and
document that device teardown belongs in Drop or PinnedDrop.

Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
---
rust/kernel/pci.rs | 34 ++++-----------------------------
samples/rust/rust_driver_pci.rs | 7 ++-----
2 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 0e9455fd544d..8101c58da6f4 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -90,7 +90,6 @@ unsafe fn register(
unsafe {
(*pdrv.get()).name = name.as_char_ptr();
(*pdrv.get()).probe = Some(Self::probe_callback);
- (*pdrv.get()).remove = Some(Self::remove_callback);
(*pdrv.get()).id_table = T::ID_TABLE.as_ptr();
}

@@ -133,21 +132,6 @@ extern "C" fn probe_callback(
Ok(0)
})
}
-
- extern "C" fn remove_callback(pdev: *mut bindings::pci_dev) {
- // SAFETY: The PCI bus only ever calls the remove callback with a valid pointer to a
- // `struct pci_dev`.
- //
- // INVARIANT: `pdev` is valid for the duration of `remove_callback()`.
- let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal<'_>>>() };
-
- // SAFETY: `remove_callback` is only ever called after a successful call to
- // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called
- // and stored a `Pin<KBox<T::Data<'_>>>`.
- let data = unsafe { pdev.as_ref().drvdata_borrow::<T::Data<'_>>() };
-
- T::unbind(pdev, data);
- }
}

/// Declares a kernel module that exposes a single PCI driver.
@@ -305,6 +289,10 @@ pub trait Driver {
type IdInfo: 'static;

/// The type of the driver's bus device private data.
+ ///
+ /// Device teardown should be performed in [`Drop`] or [`PinnedDrop`](pin_init::PinnedDrop)
+ /// for this type. The `'bound` lifetime allows the data to retain device resources and a
+ /// [`Device<device::Bound>`] reference for use during teardown.
type Data<'bound>: Send + 'bound;

/// The table of device ids supported by the driver.
@@ -318,20 +306,6 @@ fn probe<'bound>(
dev: &'bound Device<device::Core<'_>>,
id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
-
- /// PCI driver unbind.
- ///
- /// Called when a [`Device`] is unbound from its bound [`Driver`]. Implementing this callback
- /// is optional.
- ///
- /// This callback serves as a place for drivers to perform teardown operations that require a
- /// `&Device<Core>` or `&Device<Bound>` reference. For instance, drivers may try to perform I/O
- /// operations to gracefully tear down the device.
- ///
- /// Otherwise, release operations for driver resources should be performed in `Drop`.
- fn unbind<'bound>(dev: &'bound Device<device::Core<'_>>, this: Pin<&Self::Data<'bound>>) {
- let _ = (dev, this);
- }
}

/// The PCI device representation.
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index 13b035a95756..6bd4c1ff11ee 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -176,15 +176,12 @@ fn probe<'bound>(
index: *info,
})
}
-
- fn unbind<'bound>(_pdev: &'bound pci::Device<Core<'_>>, this: Pin<&Self::Data<'bound>>) {
- this.bar
- .write_reg(regs::TEST::zeroed().with_index(this.index));
- }
}

impl Drop for SampleDriverData<'_> {
fn drop(&mut self) {
+ self.bar
+ .write_reg(regs::TEST::zeroed().with_index(self.index));
dev_dbg!(self.pdev, "Remove Rust PCI driver sample.\n");
}
}
--
2.56.0