@@ -79,6 +79,14 @@ unsafe fn dec_ref(obj: NonNull<Self>) {
}
}
+impl<T: drm::drv::Driver> AsRef<device::Device> for Device<T> {
+ fn as_ref(&self) -> &device::Device {
+ // SAFETY: `bindings::drm_device::dev` is valid as long as the DRM device itself is valid,
+ // which is guaranteed by the type invariant.
+ unsafe { device::Device::as_ref((*self.as_raw()).dev) }
+ }
+}
+
// SAFETY: `Device` only holds a pointer to a C device, which is safe to be used from any thread.
unsafe impl<T: drm::drv::Driver> Send for Device<T> {}
Implement `AsRef<device::Device>` for `drm::device::Device` such that `dev_*` print macros can be used conveniently. Signed-off-by: Danilo Krummrich <dakr@redhat.com> --- rust/kernel/drm/device.rs | 8 ++++++++ 1 file changed, 8 insertions(+)