mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 07:03:28 -04:00
rust: device: move drvdata_borrow() to InternalBoundContext
Move drvdata_borrow() from impl Device<CoreInternal<'a>> to impl<Ctx: InternalBoundContext> Device<Ctx>, making it available from both CoreInternal and BoundInternal contexts. Fold drvdata_unchecked() (previously on Device<Bound>) directly into drvdata_borrow(), since it was only called from there and the generic context cannot resolve methods through the deref chain. Signed-off-by: Danilo Krummrich <dakr@kernel.org> Reviewed-By: Markus Probst <markus.probst@posteo.de> Link: https://patch.msgid.link/20260530132736.3298549-2-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
@@ -236,7 +236,9 @@ pub(crate) unsafe fn drvdata_obtain<T>(&self) -> Option<Pin<KBox<T>>> {
|
||||
// in `into_foreign()`.
|
||||
Some(unsafe { Pin::<KBox<T>>::from_foreign(ptr.cast()) })
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: InternalBoundContext> Device<Ctx> {
|
||||
/// Borrow the driver's private data bound to this [`Device`].
|
||||
///
|
||||
/// # Safety
|
||||
@@ -246,22 +248,6 @@ pub(crate) unsafe fn drvdata_obtain<T>(&self) -> Option<Pin<KBox<T>>> {
|
||||
/// - The type `T` must match the type of the `ForeignOwnable` previously stored by
|
||||
/// [`Device::set_drvdata`].
|
||||
pub unsafe fn drvdata_borrow<T>(&self) -> Pin<&T> {
|
||||
// SAFETY: `drvdata_unchecked()` has the exact same safety requirements as the ones
|
||||
// required by this method.
|
||||
unsafe { self.drvdata_unchecked() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Device<Bound> {
|
||||
/// Borrow the driver's private data bound to this [`Device`].
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - Must only be called after a preceding call to [`Device::set_drvdata`] and before
|
||||
/// the device is fully unbound.
|
||||
/// - The type `T` must match the type of the `ForeignOwnable` previously stored by
|
||||
/// [`Device::set_drvdata`].
|
||||
unsafe fn drvdata_unchecked<T>(&self) -> Pin<&T> {
|
||||
// SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`.
|
||||
let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user