]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: driver: add DriverData type to the DriverLayout trait
authorDanilo Krummrich <dakr@kernel.org>
Wed, 7 Jan 2026 10:35:04 +0000 (11:35 +0100)
committerDanilo Krummrich <dakr@kernel.org>
Fri, 16 Jan 2026 00:17:29 +0000 (01:17 +0100)
Add an associated type DriverData to the DriverLayout trait indicating
the type of the driver's device private data.

Acked-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Igor Korotin <igor.korotin.linux@gmail.com>
Link: https://patch.msgid.link/20260107103511.570525-6-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/auxiliary.rs
rust/kernel/driver.rs
rust/kernel/i2c.rs
rust/kernel/pci.rs
rust/kernel/platform.rs
rust/kernel/usb.rs

index 9b25af331ad5ceaf214e4d6ed53527e94a5b0001..17574aa5066fd94fc267c941cc46f6ae9192bb54 100644 (file)
@@ -25,10 +25,12 @@ pub struct Adapter<T: Driver>(T);
 
 // SAFETY:
 // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`.
+// - `T` is the type of the driver's device private data.
 // - `struct auxiliary_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::auxiliary_driver;
+    type DriverData = T;
     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
 }
 
index 4a96a07905d1b404d3443701d56a9246f8305db7..ba1ca1f7a7e24e7388c0caba61c7f4ecf0a166ee 100644 (file)
@@ -108,11 +108,15 @@ use pin_init::{pin_data, pinned_drop, PinInit};
 ///
 /// Implementors must guarantee that:
 /// - `DriverType` is `repr(C)`,
+/// - `DriverData` is the type of the driver's device private data.
 /// - `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;
 
+    /// The type of the driver's device private data.
+    type DriverData;
+
     /// Byte offset of the embedded `struct device_driver` within `DriverType`.
     ///
     /// This must correspond exactly to the location of the embedded `struct device_driver` field.
index d97e73282003c7bc155f9041c8fa2ed3c15cc415..e8624222708117b39ab0e25f5999316a9fdc25a1 100644 (file)
@@ -94,10 +94,12 @@ pub struct Adapter<T: Driver>(T);
 
 // SAFETY:
 // - `bindings::i2c_driver` is a C type declared as `repr(C)`.
+// - `T` is the type of the driver's device private data.
 // - `struct i2c_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::i2c_driver;
+    type DriverData = T;
     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
 }
 
index fe6f508b0cacee2e69c0532b23d462cffd459abf..590723dcb5ae3899752a88b41687d19e94023213 100644 (file)
@@ -52,10 +52,12 @@ pub struct Adapter<T: Driver>(T);
 
 // SAFETY:
 // - `bindings::pci_driver` is a C type declared as `repr(C)`.
+// - `T` is the type of the driver's device private data.
 // - `struct pci_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::pci_driver;
+    type DriverData = T;
     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
 }
 
index 716c9cc25aea2e7094764e70cb368e9315474970..b8a681df9ddc73b0d1155ad3ff89f8c47441f75b 100644 (file)
@@ -28,10 +28,12 @@ pub struct Adapter<T: Driver>(T);
 
 // SAFETY:
 // - `bindings::platform_driver` is a C type declared as `repr(C)`.
+// - `T` is the type of the driver's device private data.
 // - `struct platform_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::platform_driver;
+    type DriverData = T;
     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
 }
 
index eb1c9b9ef22869484ebedcad05990fdd916cbc36..4cf4bb1705b5079cfe7ca4215bd3872c732fd564 100644 (file)
@@ -29,10 +29,12 @@ pub struct Adapter<T: Driver>(T);
 
 // SAFETY:
 // - `bindings::usb_driver` is a C type declared as `repr(C)`.
+// - `T` is the type of the driver's device private data.
 // - `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;
+    type DriverData = T;
     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
 }