]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: devres: embed struct devres_node directly
authorDanilo Krummrich <dakr@kernel.org>
Fri, 13 Feb 2026 22:07:15 +0000 (23:07 +0100)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 17 Mar 2026 23:47:14 +0000 (00:47 +0100)
commit9aa64d2503c6f5a803ff2990608312e5bdc6b0de
tree52e3e699dd8064a1e04c8af7be20305a514c70ba
parentba424bc2c7bb3a9b81d1b6c773f1e2e7b8fffe66
rust: devres: embed struct devres_node directly

Currently, the Devres<T> container uses devm_add_action() to register a
devres callback.

devm_add_action() allocates a struct action_devres, which on top of
struct devres_node, just keeps a data pointer and release function
pointer.

This is an unnecessary indirection, given that analogous to struct
devres, the Devres<T> container can just embed a struct devres_node
directly without an additional allocation.

In contrast to struct devres, we don't need to force an alignment of
ARCH_DMA_MINALIGN (as struct devres does to account for the worst case)
since we have generics in Rust. I.e. the compiler already ensures
correct alignment of the embedded T in Devres<T>.

Thus, get rid of devm_add_action() and instead embed a struct
devres_node directly.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260213220718.82835-6-dakr@kernel.org
[ * Improve comment about core::any::type_name(),
  * add #[must_use] to devres_node_remove(),
  * use container_of!() in devres_node_free_node().

    - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/devres.rs