]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: driver: let probe() return impl PinInit<Self, Error>
authorDanilo Krummrich <dakr@kernel.org>
Thu, 16 Oct 2025 12:55:28 +0000 (14:55 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 21 Oct 2025 16:40:48 +0000 (18:40 +0200)
commit0242623384c767b1156b61b67894b4ecf6682b8b
treeaf5131064b1aac4ecdafe8884a95464429fab020
parentfc2b38de4c01710ecb9ebb9ecdce9a7bf433e9a8
rust: driver: let probe() return impl PinInit<Self, Error>

The driver model defines the lifetime of the private data stored in (and
owned by) a bus device to be valid from when the driver is bound to a
device (i.e. from successful probe()) until the driver is unbound from
the device.

This is already taken care of by the Rust implementation of the driver
model. However, we still ask drivers to return a Result<Pin<KBox<Self>>>
from probe().

Unlike in C, where we do not have the concept of initializers, but
rather deal with uninitialized memory, drivers can just return an
impl PinInit<Self, Error> instead.

This contributes to more clarity to the fact that a driver returns it's
device private data in probe() and the Rust driver model owns the data,
manages the lifetime and - considering the lifetime - provides (safe)
accessors for the driver.

Hence, let probe() functions return an impl PinInit<Self, Error> instead
of Result<Pin<KBox<Self>>>.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
18 files changed:
drivers/cpufreq/rcpufreq_dt.rs
drivers/gpu/drm/nova/driver.rs
drivers/gpu/drm/tyr/driver.rs
drivers/gpu/nova-core/driver.rs
rust/kernel/auxiliary.rs
rust/kernel/cpufreq.rs
rust/kernel/device.rs
rust/kernel/driver.rs
rust/kernel/io/mem.rs
rust/kernel/pci.rs
rust/kernel/platform.rs
rust/kernel/usb.rs
samples/rust/rust_debugfs.rs
samples/rust/rust_dma.rs
samples/rust/rust_driver_auxiliary.rs
samples/rust/rust_driver_pci.rs
samples/rust/rust_driver_platform.rs
samples/rust/rust_driver_usb.rs