aboutsummaryrefslogtreecommitdiffstats
path: root/samples
diff options
authorDanilo Krummrich <dakr@kernel.org>2026-05-25 22:21:00 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-05-27 16:23:31 +0200
commit81fdc788144348f295cfaa4b1e1edf6c74441c15 (patch)
treed0a814d64ef189889104b6f2c47a3cf401c8a900 /samples
parent16c2b8fdab7c0808ff36430b2f49569029a8f484 (diff)
downloadlinux-next-history-81fdc788144348f295cfaa4b1e1edf6c74441c15.tar.gz
rust: platform: make Driver trait lifetime-parameterized
Add a 'bound lifetime to the associated Data, changing type Data to type Data<'bound>. This allows the driver's bus device private data to capture the device / driver bound lifetime; device resources can be stored directly by reference rather than requiring Devres. The probe() and unbind() callbacks thus gain a 'bound lifetime parameter on the methods themselves; avoiding a global lifetime on the trait impl. Existing drivers set type Data<'bound> = Self, preserving the current behavior. Acked-by: Uwe Kleine-König <ukleinek@kernel.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260525202921.124698-14-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/rust/rust_debugfs.rs10
-rw-r--r--samples/rust/rust_driver_platform.rs10
-rw-r--r--samples/rust/rust_i2c_client.rs15
-rw-r--r--samples/rust/rust_soc.rs10
4 files changed, 24 insertions, 21 deletions
diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
index 37640ed336427..1f59e08aaa4b0 100644
--- a/samples/rust/rust_debugfs.rs
+++ b/samples/rust/rust_debugfs.rs
@@ -117,14 +117,14 @@ kernel::acpi_device_table!(
impl platform::Driver for RustDebugFs {
type IdInfo = ();
- type Data = Self;
+ type Data<'bound> = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
- fn probe(
- pdev: &platform::Device<Core<'_>>,
- _info: Option<&Self::IdInfo>,
- ) -> impl PinInit<Self, Error> {
+ fn probe<'bound>(
+ pdev: &'bound platform::Device<Core<'_>>,
+ _info: Option<&'bound Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> + 'bound {
RustDebugFs::new(pdev).pin_chain(|this| {
this.counter.store(91, Relaxed);
{
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 04d40f836275a..ec0d6cac4f570 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -101,14 +101,14 @@ kernel::acpi_device_table!(
impl platform::Driver for SampleDriver {
type IdInfo = Info;
- type Data = Self;
+ type Data<'bound> = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
- fn probe(
- pdev: &platform::Device<Core<'_>>,
- info: Option<&Self::IdInfo>,
- ) -> impl PinInit<Self, Error> {
+ fn probe<'bound>(
+ pdev: &'bound platform::Device<Core<'_>>,
+ info: Option<&'bound Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> + 'bound {
let dev = pdev.as_ref();
dev_dbg!(dev, "Probe Rust Platform driver sample.\n");
diff --git a/samples/rust/rust_i2c_client.rs b/samples/rust/rust_i2c_client.rs
index 3f273c754f86d..2d876f4e3ee0a 100644
--- a/samples/rust/rust_i2c_client.rs
+++ b/samples/rust/rust_i2c_client.rs
@@ -106,14 +106,14 @@ const BOARD_INFO: i2c::I2cBoardInfo =
impl platform::Driver for SampleDriver {
type IdInfo = ();
- type Data = Self;
+ type Data<'bound> = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
- fn probe(
- pdev: &platform::Device<device::Core<'_>>,
- _info: Option<&Self::IdInfo>,
- ) -> impl PinInit<Self, Error> {
+ fn probe<'bound>(
+ pdev: &'bound platform::Device<device::Core<'_>>,
+ _info: Option<&'bound Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> + 'bound {
dev_info!(
pdev.as_ref(),
"Probe Rust I2C Client registration sample.\n"
@@ -130,7 +130,10 @@ impl platform::Driver for SampleDriver {
})
}
- fn unbind(pdev: &platform::Device<device::Core<'_>>, _this: Pin<&Self>) {
+ fn unbind<'bound>(
+ pdev: &'bound platform::Device<device::Core<'_>>,
+ _this: Pin<&Self::Data<'bound>>,
+ ) {
dev_info!(
pdev.as_ref(),
"Unbind Rust I2C Client registration sample.\n"
diff --git a/samples/rust/rust_soc.rs b/samples/rust/rust_soc.rs
index c466653491d26..808d58200eb67 100644
--- a/samples/rust/rust_soc.rs
+++ b/samples/rust/rust_soc.rs
@@ -37,14 +37,14 @@ kernel::acpi_device_table!(
impl platform::Driver for SampleSocDriver {
type IdInfo = ();
- type Data = Self;
+ type Data<'bound> = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
- fn probe(
- pdev: &platform::Device<Core<'_>>,
- _info: Option<&Self::IdInfo>,
- ) -> impl PinInit<Self, Error> {
+ fn probe<'bound>(
+ pdev: &'bound platform::Device<Core<'_>>,
+ _info: Option<&'bound Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> + 'bound {
dev_dbg!(pdev, "Probe Rust SoC driver sample.\n");
let pdev = pdev.into();