Re: [PATCH v3 04/27] rust: driver core: drop drvdata before devres release
From: Gary Guo
Date: Tue May 19 2026 - 08:53:28 EST
On Sun May 17, 2026 at 1:00 AM BST, Danilo Krummrich wrote:
> Move the post_unbind_rust callback before devres_release_all() in
> device_unbind_cleanup().
>
> With drvdata() removed, the driver's bus device private data is only
> accessible by the owning driver itself. It is hence safe to drop the
> driver's bus device private data before devres actions are released.
>
> This reordering is the key enabler for Higher-Ranked Lifetime Types
> (HRT) in Rust device drivers -- it allows driver structs to hold direct
> references to devres-managed resources, because the bus device private
> data (and with it all such references) is guaranteed to be dropped while
> the underlying devres resources are still alive.
>
> Without this change, devres resources would be freed first, leaving the
> driver's bus device private data with dangling references during its
> destructor.
>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
> ---
> drivers/base/dd.c | 2 +-
> include/linux/device/driver.h | 4 ++--
> rust/kernel/driver.rs | 4 ++--
> 3 files changed, 5 insertions(+), 5 deletions(-)