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 | 44 | // - `T` is the type of the driver's device private data. |
| 45 | 45 | // - `struct auxiliary_driver` embeds a `struct device_driver`. |
| 46 | 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 | 48 | type DriverType = bindings::auxiliary_driver; |
| 49 | 49 | type DriverData = T; |
| 50 | 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 | 53 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 54 | 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 | 56 | unsafe fn register( |
| 57 | 57 | adrv: &Opaque<Self::DriverType>, |
| 58 | 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 | 82 | extern "C" fn probe_callback( |
| 83 | 83 | adev: *mut bindings::auxiliary_device, |
| 84 | 84 | id: *const bindings::auxiliary_device_id, |
| @@ -203,7 +203,7 @@ impl Device { · 202 unmodified lines | ||
| 203 | 203 | |
| 204 | 204 | impl Device<CoreInternal> { |
| 205 | 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 | 207 | let data = KBox::pin_init(data, GFP_KERNEL)?; |
| 208 | 208 | |
| 209 | 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 | 219 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 220 | 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 | 222 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. |
| 223 | 223 | let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; |
| 224 | 224 | |
| @@ -244,7 +244,7 @@ impl Device<CoreInternal> { · 19 unmodified lines | ||
| 244 | 244 | /// device is fully unbound. |
| 245 | 245 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 246 | 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 | 248 | // SAFETY: `drvdata_unchecked()` has the exact same safety requirements as the ones |
| 249 | 249 | // required by this method. |
| 250 | 250 | unsafe { self.drvdata_unchecked() } |
| @@ -260,7 +260,7 @@ impl Device<Bound> { · 9 unmodified lines | ||
| 260 | 260 | /// the device is fully unbound. |
| 261 | 261 | /// - The type `T` must match the type of the `ForeignOwnable` previously stored by |
| 262 | 262 | /// [`Device::set_drvdata`]. |
| 263 | − unsafe fn drvdata_unchecked<T: 'static>(&self) -> Pin<&T> { | |
| 263 | + unsafe fn drvdata_unchecked<T>(&self) -> Pin<&T> { | |
| 264 | 264 | // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. |
| 265 | 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 | 181 | // any thread, so `Registration` is `Send`. |
| 182 | 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 | 185 | extern "C" fn post_unbind_callback(dev: *mut bindings::device) { |
| 186 | 186 | // SAFETY: The driver core only ever calls the post unbind callback with a valid pointer to |
| 187 | 187 | // a `struct device`. |
| @@ -215,7 +215,10 @@ impl<T: RegistrationOps + 'static> Registration<T> { · 27 unmodified lines | ||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 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 | 222 | try_pin_init!(Self { |
| 220 | 223 | reg <- Opaque::try_ffi_init(|ptr: *mut T::DriverType| { |
| 221 | 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 | 96 | // - `T` is the type of the driver's device private data. |
| 97 | 97 | // - `struct i2c_driver` embeds a `struct device_driver`. |
| 98 | 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 | 100 | type DriverType = bindings::i2c_driver; |
| 101 | 101 | type DriverData = T; |
| 102 | 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 | 105 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 106 | 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 | 108 | unsafe fn register( |
| 109 | 109 | idrv: &Opaque<Self::DriverType>, |
| 110 | 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 | 155 | extern "C" fn probe_callback(idev: *mut bindings::i2c_client) -> kernel::ffi::c_int { |
| 156 | 156 | // SAFETY: The I2C bus only ever calls the probe callback with a valid pointer to a |
| 157 | 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 | 226 | type IdInfo = T::IdInfo; |
| 227 | 227 | |
| 228 | 228 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { |
| @@ -62,7 +62,7 @@ pub struct Adapter<T: Driver>(T); · 61 unmodified lines | ||
| 62 | 62 | // - `T` is the type of the driver's device private data. |
| 63 | 63 | // - `struct pci_driver` embeds a `struct device_driver`. |
| 64 | 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 | 66 | type DriverType = bindings::pci_driver; |
| 67 | 67 | type DriverData = T; |
| 68 | 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 | 71 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 72 | 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 | 74 | unsafe fn register( |
| 75 | 75 | pdrv: &Opaque<Self::DriverType>, |
| 76 | 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 | 100 | extern "C" fn probe_callback( |
| 101 | 101 | pdev: *mut bindings::pci_dev, |
| 102 | 102 | id: *const bindings::pci_device_id, |
| @@ -48,7 +48,7 @@ pub struct Adapter<T: Driver>(T); · 47 unmodified lines | ||
| 48 | 48 | // - `T` is the type of the driver's device private data. |
| 49 | 49 | // - `struct platform_driver` embeds a `struct device_driver`. |
| 50 | 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 | 52 | type DriverType = bindings::platform_driver; |
| 53 | 53 | type DriverData = T; |
| 54 | 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 | 57 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 58 | 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 | 60 | unsafe fn register( |
| 61 | 61 | pdrv: &Opaque<Self::DriverType>, |
| 62 | 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 | 95 | extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ffi::c_int { |
| 96 | 96 | // SAFETY: The platform bus only ever calls the probe callback with a valid pointer to a |
| 97 | 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 | 128 | type IdInfo = T::IdInfo; |
| 129 | 129 | |
| 130 | 130 | fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> { |
| @@ -39,7 +39,7 @@ pub struct Adapter<T: Driver>(T); · 38 unmodified lines | ||
| 39 | 39 | // - `T` is the type of the driver's device private data. |
| 40 | 40 | // - `struct usb_driver` embeds a `struct device_driver`. |
| 41 | 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 | 43 | type DriverType = bindings::usb_driver; |
| 44 | 44 | type DriverData = T; |
| 45 | 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 | 48 | // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if |
| 49 | 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 | 51 | unsafe fn register( |
| 52 | 52 | udrv: &Opaque<Self::DriverType>, |
| 53 | 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 | 77 | extern "C" fn probe_callback( |
| 78 | 78 | intf: *mut bindings::usb_interface, |
| 79 | 79 | id: *const bindings::usb_device_id, |