Re: [PATCH v2] rust: drm: fix unsound initialization in drm::Device::new
From: Gary Guo
Date: Sun May 03 2026 - 07:49:48 EST
On Fri May 1, 2026 at 11:49 AM BST, Eliot Courtney wrote:
> If pinned initialization of drm::Device::Data fails, it calls
> drm::Device::release via drm_dev_put. This materializes a reference to
> &drm::Device, but it's not fully constructed yet, because initializing
> `data` failed. It should not be dropped either. Instead, if pinned
> initialization fails, make sure drm::Device::release isn't called.
>
> Fixes: 2e9fdbe5ec7a ("rust: drm: device: drop_in_place() the drm::Device in release()")
> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
> ---
> Changes in v2:
> - stack allocate `alloc_vtable`
> - use const { &vtable } trick to help prevent future issues
> - Link to v1: https://patch.msgid.link/20260428-fix-drm-1-v1-1-755057178066@xxxxxxxxxx
> ---
> rust/kernel/drm/device.rs | 22 ++++++++++++++++------
> 1 file changed, 16 insertions(+), 6 deletions(-)