summaryrefslogtreecommitdiff
path: root/rust/kernel/usb.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/usb.rs
parent0af1a9e4629a85964a7eebe58ebd2ca37c8c21fc (diff)
downloadlinux-next-c1d4519e1c36ffa01973e23af4502e69dcd84f39.tar.gz
linux-next-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/usb.rs')
-rw-r--r--rust/kernel/usb.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index 60b761c06fbd..eb1c9b9ef228 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -29,8 +29,11 @@ pub struct Adapter<T: Driver>(T);
// SAFETY:
// - `bindings::usb_driver` is a C type declared as `repr(C)`.
+// - `struct usb_driver` embeds a `struct device_driver`.
+// - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`.
unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> {
type DriverType = bindings::usb_driver;
+ const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
}
// SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if