Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: device: narrow the generic of drvdata_obtain()

Let T be the actual private driver data type without the surrounding
box, as it leaves less room for potential bugs.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+7 -7
+1 -1
rust/kernel/auxiliary.rs
··· 85 85 // SAFETY: `remove_callback` is only ever called after a successful call to 86 86 // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called 87 87 // and stored a `Pin<KBox<T>>`. 88 - drop(unsafe { adev.as_ref().drvdata_obtain::<Pin<KBox<T>>>() }); 88 + drop(unsafe { adev.as_ref().drvdata_obtain::<T>() }); 89 89 } 90 90 } 91 91
+2 -2
rust/kernel/device.rs
··· 215 215 /// - Must only be called once after a preceding call to [`Device::set_drvdata`]. 216 216 /// - The type `T` must match the type of the `ForeignOwnable` previously stored by 217 217 /// [`Device::set_drvdata`]. 218 - pub unsafe fn drvdata_obtain<T: ForeignOwnable>(&self) -> T { 218 + pub unsafe fn drvdata_obtain<T: 'static>(&self) -> Pin<KBox<T>> { 219 219 // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. 220 220 let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; 221 221 ··· 224 224 // `into_foreign()`. 225 225 // - `dev_get_drvdata()` guarantees to return the same pointer given to `dev_set_drvdata()` 226 226 // in `into_foreign()`. 227 - unsafe { T::from_foreign(ptr.cast()) } 227 + unsafe { Pin::<KBox<T>>::from_foreign(ptr.cast()) } 228 228 } 229 229 230 230 /// Borrow the driver's private data bound to this [`Device`].
+1 -1
rust/kernel/pci.rs
··· 94 94 // SAFETY: `remove_callback` is only ever called after a successful call to 95 95 // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called 96 96 // and stored a `Pin<KBox<T>>`. 97 - let data = unsafe { pdev.as_ref().drvdata_obtain::<Pin<KBox<T>>>() }; 97 + let data = unsafe { pdev.as_ref().drvdata_obtain::<T>() }; 98 98 99 99 T::unbind(pdev, data.as_ref()); 100 100 }
+1 -1
rust/kernel/platform.rs
··· 91 91 // SAFETY: `remove_callback` is only ever called after a successful call to 92 92 // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called 93 93 // and stored a `Pin<KBox<T>>`. 94 - let data = unsafe { pdev.as_ref().drvdata_obtain::<Pin<KBox<T>>>() }; 94 + let data = unsafe { pdev.as_ref().drvdata_obtain::<T>() }; 95 95 96 96 T::unbind(pdev, data.as_ref()); 97 97 }
+2 -2
rust/kernel/usb.rs
··· 87 87 // SAFETY: `disconnect_callback` is only ever called after a successful call to 88 88 // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called 89 89 // and stored a `Pin<KBox<T>>`. 90 - let data = unsafe { dev.drvdata_obtain::<Pin<KBox<T>>>() }; 90 + let data = unsafe { dev.drvdata_obtain::<T>() }; 91 91 92 - T::disconnect(intf, data.as_ref()); 92 + T::disconnect(intf, data.data()); 93 93 } 94 94 } 95 95