[PATCH 2/4] rust: drm: ensure kmalloc() compatible Layout

Alice Ryhl aliceryhl at google.com
Mon Aug 4 14:00:48 UTC 2025


On Thu, Jul 31, 2025 at 5:49 PM Danilo Krummrich <dakr at kernel.org> wrote:
>
> drm::Device is allocated through __drm_dev_alloc() (which uses
> kmalloc()) and the driver private data, <T as drm::Driver>::Data, is
> initialized in-place.
>
> Due to the order of fields in drm::Device
>
>   pub struct Device<T: drm::Driver> {
>      dev: Opaque<bindings::drm_device>,
>      data: T::Data,
>   }
>
> even with an arbitrary large alignment requirement of T::Data it can't
> happen that the size of Device is smaller than its alignment requirement.
>
> However, let's not rely on this subtle circumstance and create a proper
> kmalloc() compatible Layout.
>
> Fixes: 1e4b8896c0f3 ("rust: drm: add device abstraction")
> Signed-off-by: Danilo Krummrich <dakr at kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl at google.com>


More information about the dri-devel mailing list