[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDK2SRUF7OG7.1HEZXR1V4ND8Z@kernel.org>
Date: Thu, 16 Oct 2025 23:48:25 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Danilo Krummrich" <dakr@...nel.org>, <gregkh@...uxfoundation.org>,
<rafael@...nel.org>
Cc: <viresh.kumar@...aro.org>, <acourbot@...dia.com>, <ira.weiny@...el.com>,
<leon@...nel.org>, <daniel.almeida@...labora.com>, <bhelgaas@...gle.com>,
<kwilczynski@...nel.org>, <abdiel.janulgue@...il.com>,
<robin.murphy@....com>, <ojeda@...nel.org>, <alex.gaynor@...il.com>,
<boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
<a.hindborg@...nel.org>, <aliceryhl@...gle.com>, <tmgross@...ch.edu>,
<rust-for-linux@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<linux-pm@...r.kernel.org>, <nouveau@...ts.freedesktop.org>,
<dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] rust: driver: let probe() return impl PinInit<Self,
Error>
On Thu Oct 16, 2025 at 2:55 PM CEST, Danilo Krummrich wrote:
> 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 contributed 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>>>.
>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
> Depends on a minor pin-init patch [1] (Benno will send it to the list
> soon). A branch with this patch and the pin-init dependency is available
> in [2].
I sent the patch to the list:
https://lore.kernel.org/all/20251016210541.650056-1-lossin@kernel.org
---
Cheers,
Benno
>
> [1] https://github.com/Rust-for-Linux/pin-init/pull/86/commits
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=probe_return
> ---
> drivers/cpufreq/rcpufreq_dt.rs | 4 +-
> drivers/gpu/drm/nova/driver.rs | 4 +-
> drivers/gpu/drm/tyr/driver.rs | 4 +-
> drivers/gpu/nova-core/driver.rs | 34 +++++++----------
> rust/kernel/auxiliary.rs | 6 +--
> rust/kernel/cpufreq.rs | 4 +-
> rust/kernel/device.rs | 9 ++++-
> rust/kernel/driver.rs | 4 +-
> rust/kernel/io/mem.rs | 8 ++--
> rust/kernel/pci.rs | 8 ++--
> rust/kernel/platform.rs | 12 +++---
> rust/kernel/usb.rs | 4 +-
> samples/rust/rust_debugfs.rs | 21 ++++++-----
> samples/rust/rust_dma.rs | 37 +++++++++----------
> samples/rust/rust_driver_auxiliary.rs | 25 +++++--------
> samples/rust/rust_driver_pci.rs | 53 +++++++++++++--------------
> samples/rust/rust_driver_platform.rs | 6 +--
> samples/rust/rust_driver_usb.rs | 5 +--
> 18 files changed, 117 insertions(+), 131 deletions(-)
Powered by blists - more mailing lists