From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Benno Lossin" <lossin@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Fiona Behrens" <me@kloenk.dev>,
"Christian Schrefl" <chrisi.schrefl@gmail.com>,
"Alban Kurti" <kurti@invicto.ai>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: pin-init: add code blocks to `[try_][pin_]init!` macros
Date: Sun, 07 Sep 2025 13:49:28 +0200 [thread overview]
Message-ID: <DCMJMXGN68E0.IZ2F31AI11JW@kernel.org> (raw)
In-Reply-To: <aL1tloBwmJnYFPpa@google.com>
On Sun Sep 7, 2025 at 1:33 PM CEST, Alice Ryhl wrote:
> On Sun, Sep 07, 2025 at 01:20:39PM +0200, Danilo Krummrich wrote:
>> On Sun Sep 7, 2025 at 12:57 PM CEST, Alice Ryhl wrote:
>> > On Fri, Sep 05, 2025 at 04:05:31PM +0200, Benno Lossin wrote:
>> >> Allow writing `_: { /* any number of statements */ }` in initializers to
>> >> run arbitrary code during initialization.
>> >>
>> >> try_init!(MyStruct {
>> >> _: {
>> >> if check_something() {
>> >> return Err(MyError);
>> >> }
>> >> },
>> >> foo: Foo::new(val),
>> >> _: {
>> >> println!("successfully initialized `MyStruct`");
>> >> },
>> >> })
>> >>
>> >> Link: https://github.com/Rust-for-Linux/pin-init/pull/84/commits/2880a9b898336e2d54f80715f00ce00f21f74d2f
>> >> Signed-off-by: Benno Lossin <lossin@kernel.org>
>> >
>> > Nice! Would it be possible to include a user so I can see it work in
>> > practice? E.g., for the irq feature?
>>
>> Devres needs this too, but the corresponding devres stuff was a fix and is in
>> the current -rc only, so that's not a candidate.
>>
>> The IRQ stuff is in driver-core-next going to Linus for v6.18, hence, using it
>> there, this patch would have to go through the driver-core tree as well.
>>
>> For me it is fine either way.
>
> It doesn't have to land together. I would be happy with:
>
> THIS CYCLE: Land just this patch.
> NEXT CYCLE: Land the irq and/or devres user.
>
> But I'd like to see it work in practice before I give a Reviewed-by.
> It's hard to evaluate this kind of macro change just from the macro
> itself.
Here's a patch for using it in devres (we backmerged -rc3 into
driver-core-next):
From 23e48f081b7ba6bebd375c6fa929f070f7977fc5 Mon Sep 17 00:00:00 2001
From: Danilo Krummrich <dakr@kernel.org>
Date: Sun, 7 Sep 2025 13:44:43 +0200
Subject: [PATCH] rust: devres: take advantage of initializer code blocks
Use pin-init initializer code blocks to register the devres action.
This resolved the TODO introduced by commit 75a7b151e808 ("rust: devres:
fix leaking call to devm_add_action()").
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/kernel/devres.rs | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
index 132545962218..430fc4880ddb 100644
--- a/rust/kernel/devres.rs
+++ b/rust/kernel/devres.rs
@@ -119,7 +119,6 @@ pub struct Devres<T: Send> {
// explicit `Send` and `Sync' impls can be removed.
#[pin]
inner: Opaque<Inner<T>>,
- _add_action: (),
}
impl<T: Send> Devres<T> {
@@ -146,10 +145,7 @@ pub fn new<'a, E>(
revoke <- Completion::new(),
data <- Revocable::new(data),
})),
- // TODO: Replace with "initializer code blocks" [1] once available.
- //
- // [1] https://github.com/Rust-for-Linux/pin-init/pull/69
- _add_action: {
+ _: {
// SAFETY: `this` is a valid pointer to uninitialized memory.
let inner = unsafe { &raw mut (*this.as_ptr()).inner };
base-commit: 544c94f0e155614551e0210074597a23d117830c
--
2.51.0
next prev parent reply other threads:[~2025-09-07 11:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 14:05 [PATCH] rust: pin-init: add code blocks to `[try_][pin_]init!` macros Benno Lossin
2025-09-07 10:57 ` Alice Ryhl
2025-09-07 11:20 ` Danilo Krummrich
2025-09-07 11:33 ` Alice Ryhl
2025-09-07 11:49 ` Danilo Krummrich [this message]
2025-09-07 17:17 ` Danilo Krummrich
2025-09-10 10:13 ` Danilo Krummrich
2025-09-10 10:19 ` Alice Ryhl
2025-09-10 22:21 ` Gary Guo
2025-09-11 2:22 ` Alexandre Courbot
2025-09-11 21:34 ` Benno Lossin
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=DCMJMXGN68E0.IZ2F31AI11JW@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=chrisi.schrefl@gmail.com \
--cc=gary@garyguo.net \
--cc=kurti@invicto.ai \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=me@kloenk.dev \
--cc=ojeda@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;
as well as URLs for NNTP newsgroup(s).