On Thu, Oct 16, 2025 at 05:08:19PM -0400, Lyude Paul wrote:
> From: Asahi Lina <[email protected]>
> 
> The DRM shmem helper includes common code useful for drivers which
> allocate GEM objects as anonymous shmem. Add a Rust abstraction for
> this. Drivers can choose the raw GEM implementation or the shmem layer,
> depending on their needs.
> 
> Signed-off-by: Asahi Lina <[email protected]>
> Signed-off-by: Daniel Almeida <[email protected]>
> Signed-off-by: Lyude Paul <[email protected]>
> +impl<T: DriverObject> gem::IntoGEMObject for Object<T> {
> +    fn as_raw(&self) -> *mut bindings::drm_gem_object {
> +        // SAFETY: Our immutable reference is proof that this is are to 
> dereference
> +        unsafe { &raw mut (*self.obj.get()).base }

Typo.

Also, in principle, this should refer to a type invariant saying that
`obj` is a valid shmem object.

> +    }
> +
> +    unsafe fn from_raw<'a>(obj: *mut bindings::drm_gem_object) -> &'a 
> Object<T> {
> +        // SAFETY: The safety contract of from_gem_obj() guarantees that 
> `obj` is contained within
> +        // `Self`
> +        unsafe {
> +            let obj: *mut Opaque<_> =
> +                container_of!(obj, bindings::drm_gem_shmem_object, 
> base).cast();

Please use Opaque::cast_from() instead of the unrestricted cast()
operation.

There are several instances of this throughout the file.

Alice

Reply via email to