[PATCH 2/7] rust: platform: remove the unbind() callback

From: Danilo Krummrich

Date: Wed Nov 11 2026 - 20:15:56 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 platform::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/platform.rs | 34 ++++-----------------------------
samples/rust/rust_i2c_client.rs | 12 ++++++------
2 files changed, 10 insertions(+), 36 deletions(-)

diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index f49aedcc94b1..09dabd6022b6 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -75,7 +75,6 @@ unsafe fn register(
unsafe {
(*pdrv.get()).driver.name = name.as_char_ptr();
(*pdrv.get()).probe = Some(Self::probe_callback);
- (*pdrv.get()).remove = Some(Self::remove_callback);
(*pdrv.get()).driver.of_match_table = of_table;
(*pdrv.get()).driver.acpi_match_table = acpi_table;
}
@@ -109,21 +108,6 @@ extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff
Ok(0)
})
}
-
- extern "C" fn remove_callback(pdev: *mut bindings::platform_device) {
- // SAFETY: The platform bus only ever calls the remove callback with a valid pointer to a
- // `struct platform_device`.
- //
- // 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);
- }
}

impl<T: Driver> driver::Adapter for Adapter<T> {
@@ -214,6 +198,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 OF device ids supported by the driver.
@@ -230,20 +218,6 @@ fn probe<'bound>(
dev: &'bound Device<device::Core<'_>>,
id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
-
- /// Platform 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 platform device representation.
diff --git a/samples/rust/rust_i2c_client.rs b/samples/rust/rust_i2c_client.rs
index c8a23875ef5b..e25492612f9c 100644
--- a/samples/rust/rust_i2c_client.rs
+++ b/samples/rust/rust_i2c_client.rs
@@ -78,7 +78,7 @@
sync::aref::ARef, //
};

-#[pin_data]
+#[pin_data(PinnedDrop)]
struct SampleDriver {
parent_dev: ARef<platform::Device>,
#[pin]
@@ -127,13 +127,13 @@ fn probe<'bound>(
}
})
}
+}

- fn unbind<'bound>(
- pdev: &'bound platform::Device<device::Core<'_>>,
- _this: Pin<&Self::Data<'bound>>,
- ) {
+#[pinned_drop]
+impl PinnedDrop for SampleDriver {
+ fn drop(self: Pin<&mut Self>) {
dev_info!(
- pdev.as_ref(),
+ self.parent_dev,
"Unbind Rust I2C Client registration sample.\n"
);
}
--
2.56.0