summaryrefslogtreecommitdiff
path: root/rust/kernel/driver.rs
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-01-07 11:35:03 +0100
committerDanilo Krummrich <dakr@kernel.org>2026-01-16 01:17:29 +0100
commitc1d4519e1c36ffa01973e23af4502e69dcd84f39 (patch)
tree26e7f83683b1feefa4a9606cdde88143bffc770f /rust/kernel/driver.rs
parent0af1a9e4629a85964a7eebe58ebd2ca37c8c21fc (diff)
downloadlwn-c1d4519e1c36ffa01973e23af4502e69dcd84f39.tar.gz
lwn-c1d4519e1c36ffa01973e23af4502e69dcd84f39.zip
rust: driver: add DEVICE_DRIVER_OFFSET to the DriverLayout trait
Add an associated const DEVICE_DRIVER_OFFSET to the DriverLayout trait indicating the offset of the embedded struct device_driver within Self::DriverType, i.e. the specific driver structs, such as struct pci_driver or struct platform_driver. Acked-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Igor Korotin <igor.korotin.linux@gmail.com> Link: https://patch.msgid.link/20260107103511.570525-5-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel/driver.rs')
-rw-r--r--rust/kernel/driver.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index 73968b13d7dc..4a96a07905d1 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -107,10 +107,16 @@ use pin_init::{pin_data, pinned_drop, PinInit};
/// # Safety
///
/// Implementors must guarantee that:
-/// - `DriverType` is `repr(C)`.
+/// - `DriverType` is `repr(C)`,
+/// - `DriverType` embeds a valid `struct device_driver` at byte offset `DEVICE_DRIVER_OFFSET`.
pub unsafe trait DriverLayout {
/// The specific driver type embedding a `struct device_driver`.
type DriverType: Default;
+
+ /// Byte offset of the embedded `struct device_driver` within `DriverType`.
+ ///
+ /// This must correspond exactly to the location of the embedded `struct device_driver` field.
+ const DEVICE_DRIVER_OFFSET: usize;
}
/// The [`RegistrationOps`] trait serves as generic interface for subsystems (e.g., PCI, Platform,