From 54b4b3aa7c5b59ca6b507ef36f8f6060bdf34f5f Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Sat, 30 May 2026 15:27:32 +0200 Subject: [PATCH] rust: device: move drvdata_borrow() to InternalBoundContext Move drvdata_borrow() from impl Device> to impl Device, making it available from both CoreInternal and BoundInternal contexts. Fold drvdata_unchecked() (previously on Device) 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 Reviewed-By: Markus Probst Link: https://patch.msgid.link/20260530132736.3298549-2-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman --- rust/kernel/device.rs | 18 ++---------------- 1 file 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 @@ pub(crate) unsafe fn drvdata_obtain(&self) -> Option>> { // in `into_foreign()`. Some(unsafe { Pin::>::from_foreign(ptr.cast()) }) } +} +impl Device { /// Borrow the driver's private data bound to this [`Device`]. /// /// # Safety @@ -246,22 +248,6 @@ pub(crate) unsafe fn drvdata_obtain(&self) -> Option>> { /// - The type `T` must match the type of the `ForeignOwnable` previously stored by /// [`Device::set_drvdata`]. pub unsafe fn drvdata_borrow(&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 { - /// 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(&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()) };