[PATCH v6 05/11] rust: device: clarify the drvdata_borrow() safety requirement

From: Simon Song

Date: Wed Nov 11 2026 - 17:50:59 EST


From: Zhi Wang <zhiw@xxxxxxxxxx>

The safety requirement of drvdata_borrow() says it must only be called
after Device::set_drvdata() and before the device is fully unbound.
This describes when the stored data is expected to be present, rather
than the requirement itself.

State the requirement directly: the data stored by
Device::set_drvdata() must still be installed and remain valid for the
returned borrow.

Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: Simon Song <xinmengs@xxxxxxxxxx>
---
rust/kernel/device.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 2291d85b6849..1f6bb58396e2 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -243,8 +243,8 @@ impl<Ctx: InternalBoundContext> Device<Ctx> {
///
/// # Safety
///
- /// - Must only be called after a preceding call to [`Device::set_drvdata`] and before the
- /// device is fully unbound.
+ /// - The data stored by [`Device::set_drvdata`] must still be installed and remain valid
+ /// for the returned borrow.
/// - 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> {
--
2.43.7