[PATCH v2 0/2] Add Opaque::cast_from
Danilo Krummrich
dakr at kernel.org
Tue Jul 15 08:27:45 UTC 2025
On Tue Jun 24, 2025 at 5:27 PM CEST, Alice Ryhl wrote:
> Since commit b20fbbc08a36 ("rust: check type of `$ptr` in
> `container_of!`") we have enforced that the field pointer passed to
> container_of! must match the declared field. This caused mismatches when
> using a pointer to bindings::x for fields of type Opaque<bindings::x>.
>
> This situation encourages the user to simply pass field.cast() to the
> container_of! macro, but this is not great because you might
> accidentally pass a *mut bindings::y when the field type is
> Opaque<bindings::x>, which would be wrong.
>
> To help catch this kind of mistake, add a new Opaque::cast_from that
> wraps a raw pointer in Opaque without changing the inner type. Also
> rename raw_get() to cast_into() for naming consistency.
>
> Signed-off-by: Alice Ryhl <aliceryhl at google.com>
For the series,
Reviewed-by: Danilo Krummrich <dakr at kernel.org>
For the DRM parts,
Acked-by: Danilo Krummrich <dakr at kernel.org>
More information about the dri-devel
mailing list