summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-05-30 15:27:32 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-07-18 16:07:22 +0200
commit54b4b3aa7c5b59ca6b507ef36f8f6060bdf34f5f (patch)
treeab6c43002048219f71c4c6a3d20901249da6b7f9 /rust/kernel
parent807be7ee6fb8d7ea63eab0277ed081d8fe83abee (diff)
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>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/device.rs18
1 files changed, 2 insertions, 16 deletions
diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 354c4045f404..b538c39982a6 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -236,7 +236,9 @@ impl<'a> Device<CoreInternal<'a>> {
// 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 @@ impl<'a> Device<CoreInternal<'a>> {
/// - 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()) };