diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index d4521ef8ed80..fb3724c09f27 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -462,6 +462,20 @@ fn as_ref(&self) -> &T::ParentDevice { } } +impl AsRef> for Device { + #[inline] + fn as_ref(&self) -> &T::ParentDevice { + let dev = (**self).as_ref().as_ref(); + + // SAFETY: A `Device` guarantees that the parent device is bound. + let dev = unsafe { dev.as_bound() }; + + // SAFETY: The DRM device was constructed in `UnregisteredDevice::new()` with a parent + // device of type `T::ParentDevice`, hence `dev` is contained in a `T::ParentDevice`. + unsafe { device::AsBusDevice::from_device(dev) } + } +} + // SAFETY: A `drm::Device` can be released from any thread. unsafe impl Send for Device {}