Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Low] Safety comment relies on an undocumented type invariant regarding the 
parent device.
--

commit b94604b443e7e44bdf48a3790177f869613bf287
Author: Danilo Krummrich <[email protected]>
rust: drm: return ParentDevice from Device AsRef

This commit changes the AsRef implementation for drm::Device to return
a reference to the typed parent bus device rather than the raw base device.

> diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
> index c32cc0f0eba03..45bacd7b227f0 100644
> --- a/rust/kernel/drm/device.rs
> +++ b/rust/kernel/drm/device.rs

[ ... ]

> @@ -450,11 +450,15 @@ unsafe fn dec_ref(obj: NonNull<Self>) {
>      }
>  }
>  
> -impl<T: drm::Driver, C: DeviceContext> AsRef<device::Device> for Device<T, 
> C> {
> -    fn as_ref(&self) -> &device::Device {
> +impl<T: drm::Driver> AsRef<T::ParentDevice<device::Normal>> for Device<T> {
> +    fn as_ref(&self) -> &T::ParentDevice<device::Normal> {
>          // 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::from_raw((*self.as_raw()).dev) }
> +        let dev = unsafe { device::Device::from_raw((*self.as_raw()).dev) };
> +
> +        // SAFETY: By the type invariant of `Device`, the parent device is 
> embedded in
> +        // `T::ParentDevice`.
> +        unsafe { device::AsBusDevice::from_device(dev) }

[Severity: Low]
This isn't a bug, but the SAFETY comment references a type invariant of
Device that doesn't appear to be documented.

Looking at the # Invariants section for the Device struct, it only states
that self.dev is a valid instance of a struct device, its data layout
remains the same across contexts, and context invariants apply.

Should the # Invariants section of Device be updated to explicitly state
that the parent device is embedded in T::ParentDevice to properly support
this safety proof?

>      }
>  }

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=12

Reply via email to