summaryrefslogtreecommitdiff
path: root/rust/kernel/platform.rs
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-05-25 22:20:58 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-05-27 16:22:42 +0200
commit24799831d631239ff21ea1bf7feee832df48b81f (patch)
tree813ff3b318f319bcca01fbae76088e4d5e2c5707 /rust/kernel/platform.rs
parentde12e48a1be3e9edc0f8bc6e37bad8f7b6f32d54 (diff)
rust: device: make Core and CoreInternal lifetime-parameterized
Device<Core> references in probe callbacks are scoped to the callback, not the full binding duration. Add a lifetime parameter to Core and CoreInternal to accurately represent this in the type system. Suggested-by: Gary Guo <gary@garyguo.net> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Eliot Courtney <ecourtney@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260525202921.124698-12-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel/platform.rs')
-rw-r--r--rust/kernel/platform.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 106a5ed57ea6..257b7084338c 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -97,7 +97,7 @@ impl<T: Driver> Adapter<T> {
// `struct platform_device`.
//
// INVARIANT: `pdev` is valid for the duration of `probe_callback()`.
- let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal>>() };
+ let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal<'_>>>() };
let info = <Self as driver::Adapter>::id_info(pdev.as_ref());
from_result(|| {
@@ -113,7 +113,7 @@ impl<T: Driver> Adapter<T> {
// `struct platform_device`.
//
// INVARIANT: `pdev` is valid for the duration of `remove_callback()`.
- let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal>>() };
+ 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
@@ -197,7 +197,7 @@ macro_rules! module_platform_driver {
/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
///
/// fn probe(
-/// _pdev: &platform::Device<Core>,
+/// _pdev: &platform::Device<Core<'_>>,
/// _id_info: Option<&Self::IdInfo>,
/// ) -> impl PinInit<Self, Error> {
/// Err(ENODEV)
@@ -227,7 +227,7 @@ pub trait Driver {
/// Called when a new platform device is added or discovered.
/// Implementers should attempt to initialize the device here.
fn probe(
- dev: &Device<device::Core>,
+ dev: &Device<device::Core<'_>>,
id_info: Option<&Self::IdInfo>,
) -> impl PinInit<Self::Data, Error>;
@@ -241,7 +241,7 @@ pub trait Driver {
/// operations to gracefully tear down the device.
///
/// Otherwise, release operations for driver resources should be performed in `Drop`.
- fn unbind(dev: &Device<device::Core>, this: Pin<&Self::Data>) {
+ fn unbind(dev: &Device<device::Core<'_>>, this: Pin<&Self::Data>) {
let _ = (dev, this);
}
}
@@ -513,7 +513,7 @@ impl Device<Bound> {
kernel::impl_device_context_deref!(unsafe { Device });
kernel::impl_device_context_into_aref!(Device);
-impl crate::dma::Device for Device<device::Core> {}
+impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}
// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {