[PATCH v2 7/8] rust: drm: gem: Add GEM object abstraction

Miguel Ojeda miguel.ojeda.sandonis at gmail.com
Mon May 12 11:41:13 UTC 2025


On Fri, Apr 11, 2025 at 1:56 AM Danilo Krummrich <dakr at kernel.org> wrote:
>
> +    fn from_gem_obj(obj: *mut bindings::drm_gem_object) -> *mut Self {
> +        // SAFETY: All of our objects are Object<T>.
> +        unsafe { crate::container_of!(obj, Object<T>, obj).cast_mut() }
> +    }

Doing something unrelated, I got a Clippy warning about this public
function not being unsafe, and while the lint talks about potentially
dereferecing a pointer, it is still the case the `container_of` uses
`byte_sub` which is why the macro requires both the in and out pointer
to be in bounds of the same allocation.

So since someone may pass any pointer here, this should be unsafe, right?

Even if that is not correct, the `// SAFETY` comment should
nevertheless explain why that holds, no?

I hope that helps.

Cheers,
Miguel


More information about the dri-devel mailing list