rust: driver: add DriverData type to the DriverLayout trait

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>

+14
+2
rust/kernel/auxiliary.rs
··· 25 26 // SAFETY: 27 // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`. 28 // - `struct auxiliary_driver` embeds a `struct device_driver`. 29 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 30 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 31 type DriverType = bindings::auxiliary_driver; 32 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 33 } 34
··· 25 26 // SAFETY: 27 // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`. 28 + // - `T` is the type of the driver's device private data. 29 // - `struct auxiliary_driver` embeds a `struct device_driver`. 30 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 31 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 32 type DriverType = bindings::auxiliary_driver; 33 + type DriverData = T; 34 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 35 } 36
+4
rust/kernel/driver.rs
··· 108 /// 109 /// Implementors must guarantee that: 110 /// - `DriverType` is `repr(C)`, 111 /// - `DriverType` embeds a valid `struct device_driver` at byte offset `DEVICE_DRIVER_OFFSET`. 112 pub unsafe trait DriverLayout { 113 /// The specific driver type embedding a `struct device_driver`. 114 type DriverType: Default; 115 116 /// Byte offset of the embedded `struct device_driver` within `DriverType`. 117 ///
··· 108 /// 109 /// Implementors must guarantee that: 110 /// - `DriverType` is `repr(C)`, 111 + /// - `DriverData` is the type of the driver's device private data. 112 /// - `DriverType` embeds a valid `struct device_driver` at byte offset `DEVICE_DRIVER_OFFSET`. 113 pub unsafe trait DriverLayout { 114 /// The specific driver type embedding a `struct device_driver`. 115 type DriverType: Default; 116 + 117 + /// The type of the driver's device private data. 118 + type DriverData; 119 120 /// Byte offset of the embedded `struct device_driver` within `DriverType`. 121 ///
+2
rust/kernel/i2c.rs
··· 94 95 // SAFETY: 96 // - `bindings::i2c_driver` is a C type declared as `repr(C)`. 97 // - `struct i2c_driver` embeds a `struct device_driver`. 98 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 99 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 100 type DriverType = bindings::i2c_driver; 101 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 102 } 103
··· 94 95 // SAFETY: 96 // - `bindings::i2c_driver` is a C type declared as `repr(C)`. 97 + // - `T` is the type of the driver's device private data. 98 // - `struct i2c_driver` embeds a `struct device_driver`. 99 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 100 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 101 type DriverType = bindings::i2c_driver; 102 + type DriverData = T; 103 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 104 } 105
+2
rust/kernel/pci.rs
··· 52 53 // SAFETY: 54 // - `bindings::pci_driver` is a C type declared as `repr(C)`. 55 // - `struct pci_driver` embeds a `struct device_driver`. 56 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 57 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 58 type DriverType = bindings::pci_driver; 59 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 60 } 61
··· 52 53 // SAFETY: 54 // - `bindings::pci_driver` is a C type declared as `repr(C)`. 55 + // - `T` is the type of the driver's device private data. 56 // - `struct pci_driver` embeds a `struct device_driver`. 57 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 58 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 59 type DriverType = bindings::pci_driver; 60 + type DriverData = T; 61 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 62 } 63
+2
rust/kernel/platform.rs
··· 28 29 // SAFETY: 30 // - `bindings::platform_driver` is a C type declared as `repr(C)`. 31 // - `struct platform_driver` embeds a `struct device_driver`. 32 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 33 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 34 type DriverType = bindings::platform_driver; 35 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 36 } 37
··· 28 29 // SAFETY: 30 // - `bindings::platform_driver` is a C type declared as `repr(C)`. 31 + // - `T` is the type of the driver's device private data. 32 // - `struct platform_driver` embeds a `struct device_driver`. 33 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 34 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 35 type DriverType = bindings::platform_driver; 36 + type DriverData = T; 37 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 38 } 39
+2
rust/kernel/usb.rs
··· 29 30 // SAFETY: 31 // - `bindings::usb_driver` is a C type declared as `repr(C)`. 32 // - `struct usb_driver` embeds a `struct device_driver`. 33 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 34 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 35 type DriverType = bindings::usb_driver; 36 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 37 } 38
··· 29 30 // SAFETY: 31 // - `bindings::usb_driver` is a C type declared as `repr(C)`. 32 + // - `T` is the type of the driver's device private data. 33 // - `struct usb_driver` embeds a `struct device_driver`. 34 // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. 35 unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { 36 type DriverType = bindings::usb_driver; 37 + type DriverData = T; 38 const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); 39 } 40