linux/samples/rust
Danilo Krummrich f5d3ef25d2 rust: devres: get rid of Devres' inner Arc
So far Devres uses an inner memory allocation and reference count, i.e.
an inner Arc, in order to ensure that the devres callback can't run into
a use-after-free in case where the Devres object is dropped while the
devres callback runs concurrently.

Instead, use a completion in order to avoid a potential UAF: In
Devres::drop(), if we detect that we can't remove the devres action
anymore, we wait for the completion that is completed from the devres
callback. If, in turn, we were able to successfully remove the devres
action, we can just go ahead.

This, again, allows us to get rid of the internal Arc, and instead let
Devres consume an `impl PinInit<T, E>` in order to return an
`impl PinInit<Devres<T>, E>`, which enables us to get away with less
memory allocations.

Additionally, having the resulting explicit synchronization in
Devres::drop() prevents potential subtle undesired side effects of the
devres callback dropping the final Arc reference asynchronously within
the devres callback.

Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250626200054.243480-4-dakr@kernel.org
[ Move '# Invariants' below '# Examples'. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-06-28 18:08:50 +02:00
..
hostprogs
Kconfig drm for 6.16-rc1 2025-05-28 09:46:39 -07:00
Makefile drm for 6.16-rc1 2025-05-28 09:46:39 -07:00
rust_configfs.rs rust: configfs: add a sample demonstrating configfs usage 2025-05-12 11:05:07 +02:00
rust_dma.rs Driver core updates for 6.15-rc1 2025-04-01 11:02:03 -07:00
rust_driver_auxiliary.rs samples: rust: add Rust auxiliary driver sample 2025-04-19 14:24:05 +02:00
rust_driver_faux.rs Driver core updates for 6.15-rc1 2025-04-01 11:02:03 -07:00
rust_driver_pci.rs rust: devres: get rid of Devres' inner Arc 2025-06-28 18:08:50 +02:00
rust_driver_platform.rs samples: rust: add ACPI match table example to platform driver 2025-06-26 23:26:15 +02:00
rust_minimal.rs rust: module: introduce authors key 2025-03-10 15:12:17 +01:00
rust_misc_device.rs Char/Misc/IIO driver updates for 6.15-rc1 2025-04-01 11:26:08 -07:00
rust_print_events.c rust: samples: add tracepoint to Rust sample 2024-11-04 16:21:44 -05:00
rust_print_main.rs rust: module: introduce authors key 2025-03-10 15:12:17 +01:00