rust: devres: replace Devres::new_foreign_owned()

Replace Devres::new_foreign_owned() with devres::register().

The current implementation of Devres::new_foreign_owned() creates a full
Devres container instance, including the internal Revocable and
completion.

However, none of that is necessary for the intended use of giving full
ownership of an object to devres and getting it dropped once the given
device is unbound.

Hence, implement devres::register(), which is limited to consume the
given data, wrap it in a KBox and drop the KBox once the given device is
unbound, without any other synchronization.

Cc: Dave Airlie <airlied@redhat.com>
Cc: Simona Vetter <simona.vetter@ffwll.ch>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250626200054.243480-3-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich
2025-06-26 22:00:40 +02:00
parent ce7c22b2e1
commit 46ae8fd738
4 changed files with 85 additions and 20 deletions

View File

@@ -13,7 +13,7 @@ use crate::{
cpu::CpuId,
cpumask,
device::{Bound, Device},
devres::Devres,
devres,
error::{code::*, from_err_ptr, from_result, to_result, Result, VTABLE_DEFAULT_ERROR},
ffi::{c_char, c_ulong},
prelude::*,
@@ -1046,10 +1046,13 @@ impl<T: Driver> Registration<T> {
/// Same as [`Registration::new`], but does not return a [`Registration`] instance.
///
/// Instead the [`Registration`] is owned by [`Devres`] and will be revoked / dropped, once the
/// Instead the [`Registration`] is owned by [`devres::register`] and will be dropped, once the
/// device is detached.
pub fn new_foreign_owned(dev: &Device<Bound>) -> Result {
Devres::new_foreign_owned(dev, Self::new()?, GFP_KERNEL)
pub fn new_foreign_owned(dev: &Device<Bound>) -> Result
where
T: 'static,
{
devres::register(dev, Self::new()?, GFP_KERNEL)
}
}