[PATCH v2 01/21] rust: devres: allow to borrow a reference to the resource's Device

Alexandre Courbot
2025-05-01T12:58:59Z

Functions that take a &Devres as argument might need to print error
messages related on behalf the device. Providing the reference here
removes the need for drivers to store their own for that sole purpose.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/devres.rs | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
index 1e58f5d22044192449658a5a763c972ef11f1790..cc9702e31e8c60999ec873d9290c69be7843e774 100644
--- a/rust/kernel/devres.rs
+++ b/rust/kernel/devres.rs
@@ -196,3 +196,9 @@ fn drop(&mut self) {
DevresInner::remove_action(&self.0);
}
}
+
+impl<T> AsRef<Device> for Devres<T> {
+ fn as_ref(&self) -> &Device {
+ &self.0.dev
+ }
+}

--
2.49.0