From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 764831991C9; Sun, 7 Sep 2025 11:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757245773; cv=none; b=dzYMwk5TYKR5kfofat5f+LUuzYI/Uww5L3XNRt9V86QcqWMQBsJ5iYDFTHB4RGdzxnHxIoGtlED5tdcUmAhKHN9g3PbrIiIQD0GGYAzi/XtXkOMwZoymjbkzHGGpjeR0m9FoJJe6wt0xapZTwMdMFYgNPSrLBwZx3yf2N08Dx4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757245773; c=relaxed/simple; bh=aIdhlvipyo2+0PeyQWDF3eftzsmA1c2NyjjqT0eU764=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=Y+TBjnuXHhm+DB5e5lo3BfvhhqNUp/wncexhSMPLEJoKvPiX0u13KuELt9ZibAzVFqeNEoVKODp3dUHq6daV2Ap2GDiNOv/zpfnDVde+QpMt4V599eK/vQxysqaWLca468RhyiTy6Kdcz7ZivavpdVkD/d2rU4n0CNnyw7p31lw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b2YkkkLc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b2YkkkLc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27B88C4CEF0; Sun, 7 Sep 2025 11:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757245773; bh=aIdhlvipyo2+0PeyQWDF3eftzsmA1c2NyjjqT0eU764=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=b2YkkkLc+dGfx3ZjDLU5dsOg9R4XIg0hxranpL9139I6xYZ7xJCaFK+glzyeI9+fo KEJGfXq1VGvaUGy1SaoLjk1IC9f5xFa1Au7RVhW3nztY/qhU1HCjc9JYqFwXgl6Wed YxI2OoHXEkkWj8QCQQPJSlBb2B1uRjqWhdo8pzAZgbFth2gHLlxGvpczcwudpHIXup gEJZ4PuoNGyMtFWPnYkSmB5haPTdIsg1LPIbth0stNwkRuZ/zYnKwoOaf3iA70jWa3 we0eaH1e/Nlf5LdQBVAcON6HuCD5Ux2cGuzpd69c/ULfIIn9nhO6mrpfXrS+LeNJI+ KUJahWylYrZWg== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 07 Sep 2025 13:49:28 +0200 Message-Id: Subject: Re: [PATCH] rust: pin-init: add code blocks to `[try_][pin_]init!` macros Cc: "Benno Lossin" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Trevor Gross" , "Fiona Behrens" , "Christian Schrefl" , "Alban Kurti" , , To: "Alice Ryhl" From: "Danilo Krummrich" References: <20250905140534.3328297-1-lossin@kernel.org> In-Reply-To: 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. >> >>=20 >> >> try_init!(MyStruct { >> >> _: { >> >> if check_something() { >> >> return Err(MyError); >> >> } >> >> }, >> >> foo: Foo::new(val), >> >> _: { >> >> println!("successfully initialized `MyStruct`"); >> >> }, >> >> }) >> >>=20 >> >> Link: https://github.com/Rust-for-Linux/pin-init/pull/84/commits/2880= a9b898336e2d54f80715f00ce00f21f74d2f >> >> Signed-off-by: Benno Lossin >> > >> > Nice! Would it be possible to include a user so I can see it work in >> > practice? E.g., for the irq feature? >>=20 >> 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. >>=20 >> The IRQ stuff is in driver-core-next going to Linus for v6.18, hence, us= ing it >> there, this patch would have to go through the driver-core tree as well. >>=20 >> 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 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 --- 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 { // explicit `Send` and `Sync' impls can be removed. #[pin] inner: Opaque>, - _add_action: (), } impl Devres { @@ -146,10 +145,7 @@ pub fn new<'a, E>( revoke <- Completion::new(), data <- Revocable::new(data), })), - // TODO: Replace with "initializer code blocks" [1] once avail= able. - // - // [1] https://github.com/Rust-for-Linux/pin-init/pull/69 - _add_action: { + _: { // SAFETY: `this` is a valid pointer to uninitialized memo= ry. let inner =3D unsafe { &raw mut (*this.as_ptr()).inner }; base-commit: 544c94f0e155614551e0210074597a23d117830c -- 2.51.0