]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: driver core: drop drvdata before devres release
authorDanilo Krummrich <dakr@kernel.org>
Mon, 25 May 2026 20:20:52 +0000 (22:20 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 27 May 2026 14:22:41 +0000 (16:22 +0200)
commitbe31fcf5af751815457102575b816a2bd31b4562
tree16eab742f21d9e6739e26ede27b86a0ed144660b
parent7fdffdda630ee61ae0e09ef8f1ace52bbf70e2b0
rust: driver core: drop drvdata before devres release

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.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260525202921.124698-6-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/base/dd.c
include/linux/device/driver.h
rust/kernel/driver.rs