summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2025-10-21 00:34:26 +0200
committerDanilo Krummrich <dakr@kernel.org>2025-10-29 18:29:32 +0100
commite4e679c8608e5c747081cc6ce63ee0b0e524c68d (patch)
treeba5c0a8dbb8abd3efae0bab5de059bc69c2b2e75 /samples
parent589b061975db3c7e87b819cc9a8006eb99ac4b5f (diff)
rust: auxiliary: unregister on parent device unbind
Guarantee that an auxiliary driver will be unbound before its parent is unbound; there is no point in operating an auxiliary device whose parent has been unbound. In practice, this guarantee allows us to assume that for a bound auxiliary device, also the parent device is bound. This is useful when an auxiliary driver calls into its parent, since it allows the parent to directly access device resources and its device private data due to the guaranteed bound device context. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/rust/rust_driver_auxiliary.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 2e9afeb83d4f..95c552ee9489 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -5,7 +5,8 @@
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
use kernel::{
- auxiliary, c_str, device::Core, driver, error::Error, pci, prelude::*, InPlaceModule,
+ auxiliary, c_str, device::Core, devres::Devres, driver, error::Error, pci, prelude::*,
+ InPlaceModule,
};
use pin_init::PinInit;
@@ -40,8 +41,12 @@ impl auxiliary::Driver for AuxiliaryDriver {
}
}
+#[pin_data]
struct ParentDriver {
- _reg: [auxiliary::Registration; 2],
+ #[pin]
+ _reg0: Devres<auxiliary::Registration>,
+ #[pin]
+ _reg1: Devres<auxiliary::Registration>,
}
kernel::pci_device_table!(
@@ -57,11 +62,9 @@ impl pci::Driver for ParentDriver {
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
- Ok(Self {
- _reg: [
- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 0, MODULE_NAME)?,
- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 1, MODULE_NAME)?,
- ],
+ try_pin_init!(Self {
+ _reg0 <- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 0, MODULE_NAME),
+ _reg1 <- auxiliary::Registration::new(pdev.as_ref(), AUXILIARY_NAME, 1, MODULE_NAME),
})
}
}