summaryrefslogtreecommitdiff
path: root/samples/rust
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-05-25 22:21:10 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-05-27 16:27:28 +0200
commit4555291ddae9abe2c40a7eae192b1976b07a1fad (patch)
tree8418932505f646ddb7758774938f01c81fba0983 /samples/rust
parente189bdb687a56bcf389798f1d3a2f261fff2ef54 (diff)
rust: auxiliary: generalize Registration over ForLt
Generalize Registration<T> to Registration<F: ForLt> and Device::registration_data<F: ForLt>() to return Pin<&F::Of<'_>>. The stored 'static lifetime is shortened to the borrow lifetime of &self via ForLt::cast_ref; ForLt's covariance guarantee makes this sound. 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-24-dakr@kernel.org [ Use PhantomData<F::Of<'a>> instead of PhantomData<(fn(&'a ()) -> &'a (), F)>], which also gets us rid of #[allow(clippy::type_complexity)]. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples/rust')
-rw-r--r--samples/rust/rust_driver_auxiliary.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index b30a4d5cdf8a..e3e811a14110 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -10,10 +10,10 @@ use kernel::{
Bound,
Core, //
},
- devres::Devres,
driver,
pci,
prelude::*,
+ types::ForLt,
InPlaceModule, //
};
@@ -55,9 +55,12 @@ struct Data {
index: u32,
}
-struct ParentDriver {
- _reg0: Devres<auxiliary::Registration<Data>>,
- _reg1: Devres<auxiliary::Registration<Data>>,
+struct ParentDriver;
+
+#[allow(clippy::type_complexity)]
+struct ParentData<'bound> {
+ _reg0: auxiliary::Registration<'bound, ForLt!(Data)>,
+ _reg1: auxiliary::Registration<'bound, ForLt!(Data)>,
}
kernel::pci_device_table!(
@@ -69,15 +72,15 @@ kernel::pci_device_table!(
impl pci::Driver for ParentDriver {
type IdInfo = ();
- type Data<'bound> = Self;
+ type Data<'bound> = ParentData<'bound>;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
_info: &'bound Self::IdInfo,
- ) -> impl PinInit<Self, Error> + 'bound {
- Ok(Self {
+ ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
+ Ok(ParentData {
_reg0: auxiliary::Registration::new(
pdev.as_ref(),
AUXILIARY_NAME,
@@ -101,7 +104,7 @@ impl ParentDriver {
let dev = adev.parent();
let pdev: &pci::Device<Bound> = dev.try_into()?;
- let data = adev.registration_data::<Data>()?;
+ let data = adev.registration_data::<ForLt!(Data)>()?;
dev_info!(
dev,