With the ForeignOwnable lifetime change, the 'static bound is no longer necessary on the drvdata methods or bus adapter impls. Move it to the Registration constructor instead.
Showing the changes to rust/kernel (7 of 7 files). Show all
Unified · Split
| @@ -44,7 +44,7 @@ pub struct Adapter<T: Driver>(T); · 43 unmodified lines | |||
| 44 | // - `T` is the type of the driver's device private data. | 44 | // - `T` is the type of the driver's device private data. |
| 45 | // - `struct auxiliary_driver` embeds a `struct device_driver`. | 45 | // - `struct auxiliary_driver` embeds a `struct device_driver`. |
| 46 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. | 46 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. |
| 47 | unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { | 47 | unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> { |
| 48 | type DriverType = bindings::auxiliary_driver; | 48 | type DriverType = bindings::auxiliary_driver; |
| 49 | type DriverData = T; | 49 | type DriverData = T; |
| 50 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); | 50 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); |
| @@ -52,7 +52,7 @@ unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { · 1 unmodified line | |||
| 52 | 52 | ||
| 53 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if | 53 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 54 | // a preceding call to `register` has been successful. | 54 | // a preceding call to `register` has been successful. |
| 55 | unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { | 55 | unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> { |
| 56 | unsafe fn register( | 56 | unsafe fn register( |
| 57 | adrv: &Opaque<Self::DriverType>, | 57 | adrv: &Opaque<Self::DriverType>, |
| 58 | name: &'static CStr, | 58 | name: &'static CStr, |
| @@ -78,7 +78,7 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { · 19 unmodified lines | |||
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | impl<T: Driver + 'static> Adapter<T> { | 81 | impl<T: Driver> Adapter<T> { |
| 82 | extern "C" fn probe_callback( | 82 | extern "C" fn probe_callback( |
| 83 | adev: *mut bindings::auxiliary_device, | 83 | adev: *mut bindings::auxiliary_device, |
| 84 | id: *const bindings::auxiliary_device_id, | 84 | id: *const bindings::auxiliary_device_id, |
| @@ -203,7 +203,7 @@ impl Device { · 202 unmodified lines | |||
| 203 | 203 | ||
| 204 | impl Device<CoreInternal> { | 204 | impl Device<CoreInternal> { |
| 205 | /// Store a pointer to the bound driver's private data. | 205 | /// Store a pointer to the bound driver's private data. |
| 206 | pub fn set_drvdata<T: 'static>(&self, data: impl PinInit<T, Error>) -> Result { | 206 | pub fn set_drvdata<T>(&self, data: impl PinInit<T, Error>) -> Result { |
| 207 | let data = KBox::pin_init(data, GFP_KERNEL)?; | 207 | let data = KBox::pin_init(data, GFP_KERNEL)?; |
| 208 | 208 | ||
| 209 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. | 209 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. |
| @@ -218,7 +218,7 @@ impl Device<CoreInternal> { · 8 unmodified lines | |||
| 218 | /// | 218 | /// |
| 219 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by | 219 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 220 | /// [`Device::set_drvdata`]. | 220 | /// [`Device::set_drvdata`]. |
| 221 | pub(crate) unsafe fn drvdata_obtain<T: 'static>(&self) -> Option<Pin<KBox<T>>> { | 221 | pub(crate) unsafe fn drvdata_obtain<T>(&self) -> Option<Pin<KBox<T>>> { |
| 222 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. | 222 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. |
| 223 | let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; | 223 | let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; |
| 224 | 224 | ||
| @@ -244,7 +244,7 @@ impl Device<CoreInternal> { · 19 unmodified lines | |||
| 244 | /// device is fully unbound. | 244 | /// device is fully unbound. |
| 245 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by | 245 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 246 | /// [`Device::set_drvdata`]. | 246 | /// [`Device::set_drvdata`]. |
| 247 | pub unsafe fn drvdata_borrow<T: 'static>(&self) -> Pin<&T> { | 247 | pub unsafe fn drvdata_borrow<T>(&self) -> Pin<&T> { |
| 248 | // SAFETY: `drvdata_unchecked()` has the exact same safety requirements as the ones | 248 | // SAFETY: `drvdata_unchecked()` has the exact same safety requirements as the ones |
| 249 | // required by this method. | 249 | // required by this method. |
| 250 | unsafe { self.drvdata_unchecked() } | 250 | unsafe { self.drvdata_unchecked() } |
| @@ -260,7 +260,7 @@ impl Device<Bound> { · 9 unmodified lines | |||
| 260 | /// the device is fully unbound. | 260 | /// the device is fully unbound. |
| 261 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by | 261 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 262 | /// [`Device::set_drvdata`]. | 262 | /// [`Device::set_drvdata`]. |
| 263 | unsafe fn drvdata_unchecked<T: 'static>(&self) -> Pin<&T> { | 263 | unsafe fn drvdata_unchecked<T>(&self) -> Pin<&T> { |
| 264 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. | 264 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. |
| 265 | let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; | 265 | let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; |
| 266 | 266 | ||
| @@ -181,7 +181,7 @@ unsafe impl<T: RegistrationOps> Sync for Registration<T> {} · 180 unmodified lines | |||
| 181 | // any thread, so `Registration` is `Send`. | 181 | // any thread, so `Registration` is `Send`. |
| 182 | unsafe impl<T: RegistrationOps> Send for Registration<T> {} | 182 | unsafe impl<T: RegistrationOps> Send for Registration<T> {} |
| 183 | 183 | ||
| 184 | impl<T: RegistrationOps + 'static> Registration<T> { | 184 | impl<T: RegistrationOps> Registration<T> { |
| 185 | extern "C" fn post_unbind_callback(dev: *mut bindings::device) { | 185 | extern "C" fn post_unbind_callback(dev: *mut bindings::device) { |
| 186 | // SAFETY: The driver core only ever calls the post unbind callback with a valid pointer to | 186 | // SAFETY: The driver core only ever calls the post unbind callback with a valid pointer to |
| 187 | // a `struct device`. | 187 | // a `struct device`. |
| @@ -215,7 +215,10 @@ impl<T: RegistrationOps + 'static> Registration<T> { · 27 unmodified lines | |||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | /// Creates a new instance of the registration object. | 217 | /// Creates a new instance of the registration object. |
| 218 | pub fn new(name: &'static CStr, module: &'static ThisModule) -> impl PinInit<Self, Error> { | 218 | pub fn new(name: &'static CStr, module: &'static ThisModule) -> impl PinInit<Self, Error> |
| 219 | where | ||
| 220 | T: 'static, | ||
| 221 | { | ||
| 219 | try_pin_init!(Self { | 222 | try_pin_init!(Self { |
| 220 | reg <- Opaque::try_ffi_init(|ptr: *mut T::DriverType| { | 223 | reg <- Opaque::try_ffi_init(|ptr: *mut T::DriverType| { |
| 221 | // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. | 224 | // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. |
| @@ -96,7 +96,7 @@ pub struct Adapter<T: Driver>(T); · 95 unmodified lines | |||
| 96 | // - `T` is the type of the driver's device private data. | 96 | // - `T` is the type of the driver's device private data. |
| 97 | // - `struct i2c_driver` embeds a `struct device_driver`. | 97 | // - `struct i2c_driver` embeds a `struct device_driver`. |
| 98 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `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> { | 99 | unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> { |
| 100 | type DriverType = bindings::i2c_driver; | 100 | type DriverType = bindings::i2c_driver; |
| 101 | type DriverData = T; | 101 | type DriverData = T; |
| 102 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); | 102 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); |
| @@ -104,7 +104,7 @@ unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { · 1 unmodified line | |||
| 104 | 104 | ||
| 105 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if | 105 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 106 | // a preceding call to `register` has been successful. | 106 | // a preceding call to `register` has been successful. |
| 107 | unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { | 107 | unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> { |
| 108 | unsafe fn register( | 108 | unsafe fn register( |
| 109 | idrv: &Opaque<Self::DriverType>, | 109 | idrv: &Opaque<Self::DriverType>, |
| 110 | name: &'static CStr, | 110 | name: &'static CStr, |
| @@ -151,7 +151,7 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { · 40 unmodified lines | |||
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | impl<T: Driver + 'static> Adapter<T> { | 154 | impl<T: Driver> Adapter<T> { |
| 155 | extern "C" fn probe_callback(idev: *mut bindings::i2c_client) -> kernel::ffi::c_int { | 155 | extern "C" fn probe_callback(idev: *mut bindings::i2c_client) -> kernel::ffi::c_int { |
| 156 | // SAFETY: The I2C bus only ever calls the probe callback with a valid pointer to a | 156 | // SAFETY: The I2C bus only ever calls the probe callback with a valid pointer to a |
| 157 | // `struct i2c_client`. | 157 | // `struct i2c_client`. |
| @@ -222,7 +222,7 @@ impl<T: Driver + 'static> Adapter<T> { · 64 unmodified lines | |||
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | impl<T: Driver + 'static> driver::Adapter for Adapter<T> { | 225 | impl<T: Driver> driver::Adapter for Adapter<T> { |
| 226 | type IdInfo = T::IdInfo; | 226 | type IdInfo = T::IdInfo; |
| 227 | 227 | ||
| 228 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { | 228 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { |
| @@ -62,7 +62,7 @@ pub struct Adapter<T: Driver>(T); · 61 unmodified lines | |||
| 62 | // - `T` is the type of the driver's device private data. | 62 | // - `T` is the type of the driver's device private data. |
| 63 | // - `struct pci_driver` embeds a `struct device_driver`. | 63 | // - `struct pci_driver` embeds a `struct device_driver`. |
| 64 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. | 64 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. |
| 65 | unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { | 65 | unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> { |
| 66 | type DriverType = bindings::pci_driver; | 66 | type DriverType = bindings::pci_driver; |
| 67 | type DriverData = T; | 67 | type DriverData = T; |
| 68 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); | 68 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); |
| @@ -70,7 +70,7 @@ unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { · 1 unmodified line | |||
| 70 | 70 | ||
| 71 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if | 71 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 72 | // a preceding call to `register` has been successful. | 72 | // a preceding call to `register` has been successful. |
| 73 | unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { | 73 | unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> { |
| 74 | unsafe fn register( | 74 | unsafe fn register( |
| 75 | pdrv: &Opaque<Self::DriverType>, | 75 | pdrv: &Opaque<Self::DriverType>, |
| 76 | name: &'static CStr, | 76 | name: &'static CStr, |
| @@ -96,7 +96,7 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { · 19 unmodified lines | |||
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | impl<T: Driver + 'static> Adapter<T> { | 99 | impl<T: Driver> Adapter<T> { |
| 100 | extern "C" fn probe_callback( | 100 | extern "C" fn probe_callback( |
| 101 | pdev: *mut bindings::pci_dev, | 101 | pdev: *mut bindings::pci_dev, |
| 102 | id: *const bindings::pci_device_id, | 102 | id: *const bindings::pci_device_id, |
| @@ -48,7 +48,7 @@ pub struct Adapter<T: Driver>(T); · 47 unmodified lines | |||
| 48 | // - `T` is the type of the driver's device private data. | 48 | // - `T` is the type of the driver's device private data. |
| 49 | // - `struct platform_driver` embeds a `struct device_driver`. | 49 | // - `struct platform_driver` embeds a `struct device_driver`. |
| 50 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. | 50 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. |
| 51 | unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { | 51 | unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> { |
| 52 | type DriverType = bindings::platform_driver; | 52 | type DriverType = bindings::platform_driver; |
| 53 | type DriverData = T; | 53 | type DriverData = T; |
| 54 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); | 54 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); |
| @@ -56,7 +56,7 @@ unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { · 1 unmodified line | |||
| 56 | 56 | ||
| 57 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if | 57 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 58 | // a preceding call to `register` has been successful. | 58 | // a preceding call to `register` has been successful. |
| 59 | unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { | 59 | unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> { |
| 60 | unsafe fn register( | 60 | unsafe fn register( |
| 61 | pdrv: &Opaque<Self::DriverType>, | 61 | pdrv: &Opaque<Self::DriverType>, |
| 62 | name: &'static CStr, | 62 | name: &'static CStr, |
| @@ -91,7 +91,7 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { · 28 unmodified lines | |||
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | impl<T: Driver + 'static> Adapter<T> { | 94 | impl<T: Driver> Adapter<T> { |
| 95 | extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ffi::c_int { | 95 | extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ffi::c_int { |
| 96 | // SAFETY: The platform bus only ever calls the probe callback with a valid pointer to a | 96 | // SAFETY: The platform bus only ever calls the probe callback with a valid pointer to a |
| 97 | // `struct platform_device`. | 97 | // `struct platform_device`. |
| @@ -124,7 +124,7 @@ impl<T: Driver + 'static> Adapter<T> { · 26 unmodified lines | |||
| 124 | } | 124 | } |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | impl<T: Driver + 'static> driver::Adapter for Adapter<T> { | 127 | impl<T: Driver> driver::Adapter for Adapter<T> { |
| 128 | type IdInfo = T::IdInfo; | 128 | type IdInfo = T::IdInfo; |
| 129 | 129 | ||
| 130 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { | 130 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { |
| @@ -39,7 +39,7 @@ pub struct Adapter<T: Driver>(T); · 38 unmodified lines | |||
| 39 | // - `T` is the type of the driver's device private data. | 39 | // - `T` is the type of the driver's device private data. |
| 40 | // - `struct usb_driver` embeds a `struct device_driver`. | 40 | // - `struct usb_driver` embeds a `struct device_driver`. |
| 41 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. | 41 | // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`. |
| 42 | unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { | 42 | unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> { |
| 43 | type DriverType = bindings::usb_driver; | 43 | type DriverType = bindings::usb_driver; |
| 44 | type DriverData = T; | 44 | type DriverData = T; |
| 45 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); | 45 | const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver); |
| @@ -47,7 +47,7 @@ unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> { · 1 unmodified line | |||
| 47 | 47 | ||
| 48 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if | 48 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 49 | // a preceding call to `register` has been successful. | 49 | // a preceding call to `register` has been successful. |
| 50 | unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { | 50 | unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> { |
| 51 | unsafe fn register( | 51 | unsafe fn register( |
| 52 | udrv: &Opaque<Self::DriverType>, | 52 | udrv: &Opaque<Self::DriverType>, |
| 53 | name: &'static CStr, | 53 | name: &'static CStr, |
| @@ -73,7 +73,7 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> { · 19 unmodified lines | |||
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | impl<T: Driver + 'static> Adapter<T> { | 76 | impl<T: Driver> Adapter<T> { |
| 77 | extern "C" fn probe_callback( | 77 | extern "C" fn probe_callback( |
| 78 | intf: *mut bindings::usb_interface, | 78 | intf: *mut bindings::usb_interface, |
| 79 | id: *const bindings::usb_device_id, | 79 | id: *const bindings::usb_device_id, |