From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>,
<gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<ojeda@kernel.org>, <boqun@kernel.org>, <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<a.hindborg@kernel.org>, <aliceryhl@google.com>,
<tmgross@umich.edu>
Cc: <driver-core@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH] rust: devres: add 'static bound to Devres<T>
Date: Wed, 27 May 2026 15:44:48 +0100 [thread overview]
Message-ID: <DITJFWVQH4ZF.1HYM0UDBMWQ2J@garyguo.net> (raw)
In-Reply-To: <20260526000447.350558-1-dakr@kernel.org>
On Tue May 26, 2026 at 1:04 AM BST, Danilo Krummrich wrote:
> Devres::new() registers a callback with the C devres subsystem via
> devres_node_add(). If the Devres is leaked (e.g. via
> core::mem::forget(), which is safe), its Drop impl never runs, and the
> devres release callback will revoke the inner Revocable on device
> unbind, which drops T in place. If T contains non-'static references,
> those may be dangling by that point.
>
> Add a 'static bound to prevent storing types with borrowed data in
> Devres.
The bound should be added on `Devres::new` instead.
Best,
Gary
>
> Fixes: 76c01ded724b ("rust: add devres abstraction")
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> rust/kernel/devres.rs | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
> index 9e5f93aed20c..2e258d31a45c 100644
> --- a/rust/kernel/devres.rs
> +++ b/rust/kernel/devres.rs
> @@ -122,7 +122,7 @@ struct Inner<T> {
> /// # Ok(())
> /// # }
> /// ```
> -pub struct Devres<T: Send> {
> +pub struct Devres<T: Send + 'static> {
> dev: ARef<Device>,
> inner: Arc<Inner<T>>,
> }
> @@ -184,7 +184,7 @@ pub(super) unsafe fn devres_node_remove(
> }
> }
>
> -impl<T: Send> Devres<T> {
> +impl<T: Send + 'static> Devres<T> {
> /// Creates a new [`Devres`] instance of the given `data`.
> ///
> /// The `data` encapsulated within the returned `Devres` instance' `data` will be
> @@ -349,7 +349,7 @@ unsafe impl<T: Send> Send for Devres<T> {}
> // SAFETY: `Devres` can be shared with any task, if `T: Sync`.
> unsafe impl<T: Send + Sync> Sync for Devres<T> {}
>
> -impl<T: Send> Drop for Devres<T> {
> +impl<T: Send + 'static> Drop for Devres<T> {
> fn drop(&mut self) {
> // SAFETY: When `drop` runs, it is guaranteed that nobody is accessing the revocable data
> // anymore, hence it is safe not to wait for the grace period to finish.
>
> base-commit: 56785dcb2ef6d3cff82ac33f2e34db94377416a3
next prev parent reply other threads:[~2026-05-27 14:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 0:04 Danilo Krummrich
2026-05-26 0:09 ` Danilo Krummrich
2026-05-26 1:08 ` Eliot Courtney
2026-05-26 1:49 ` Alexandre Courbot
2026-05-27 14:44 ` Gary Guo [this message]
2026-05-27 18:04 ` Danilo Krummrich
2026-05-27 18:07 ` Gary Guo
2026-05-27 18:13 ` Danilo Krummrich
2026-05-27 19:25 ` Gary Guo
2026-05-27 19:49 ` Danilo Krummrich
2026-05-28 23:10 ` Danilo Krummrich
2026-05-28 23:10 ` Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DITJFWVQH4ZF.1HYM0UDBMWQ2J@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®