From: "Danilo Krummrich" <dakr@kernel.org>
To: "Boqun Feng" <boqun.feng@gmail.com>
Cc: "Benno Lossin" <lossin@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Fiona Behrens" <me@kloenk.dev>, "Alban Kurti" <kurti@invicto.ai>,
"Alexandre Courbot" <acourbot@nvidia.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: pin-init: add references to previously initialized fields
Date: Fri, 05 Sep 2025 20:38:11 +0200 [thread overview]
Message-ID: <DCL32RUQ6Z56.1ERY7JBK6O1J6@kernel.org> (raw)
In-Reply-To: <aLscLsY0Sv1Qwgni@tardis-2.local>
(Cc: Alex)
On Fri Sep 5, 2025 at 7:21 PM CEST, Boqun Feng wrote:
> On Fri, Sep 05, 2025 at 04:00:46PM +0200, Benno Lossin wrote:
>> After initializing a field in an initializer macro, create a variable
>> holding a reference that points at that field. The type is either
>> `Pin<&mut T>` or `&mut T` depending on the field's structural pinning
>> kind.
>>
>
> It's hard to review because of lack of examples. Could you or Danilo
> share some sample usages? Thanks!
Sure, here's an example. Eventually, it's going to be a bit more complicated,
but basically that's it.
#[pin_data(PinnedDrop)]
pub(crate) struct Gpu {
spec: Spec,
bar: Arc<Devres<Bar0>>,
sysmem_flush: SysmemFlush,
gsp_falcon: Falcon<Gsp>,
sec2_falcon: Falcon<Sec2>,
#[pin]
gsp: Gsp,
}
impl Gpu {
pub(crate) fn new(
dev: &Device<Bound>,
bar: Arc<Devres<Bar0>>,
) -> impl PinInit<Self, Error> + '_ {
try_pin_init(Self {
bar,
spec: Spec::new(bar.access(dev)?)?,
gsp_falcon: Falcon::<Gsp>::new(dev, spec.chipset)?,
sec2_falcon: Falcon::<Sec2>::new(dev, spec.chipset)?,
sysmem_flush: SysmemFlush::register(dev, bar.access(dev)?, spec.chipset)?
gsp <- Gsp::new(gsp_falcon, sec2_falcon, sysmem_flush)?,
})
}
}
Imagine how much unsafe pointer mess this needs without this patch. :)
next prev parent reply other threads:[~2025-09-05 18:38 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 14:00 [PATCH] rust: pin-init: add references to previously initialized fields Benno Lossin
2025-09-05 17:18 ` Benno Lossin
2025-09-05 17:44 ` Boqun Feng
2025-09-06 10:52 ` Danilo Krummrich
2025-09-07 1:57 ` Boqun Feng
2025-09-07 2:07 ` Boqun Feng
2025-09-07 8:41 ` Benno Lossin
2025-09-07 17:29 ` Danilo Krummrich
2025-09-07 21:06 ` Benno Lossin
2025-09-07 21:39 ` Danilo Krummrich
2025-09-07 22:51 ` Benno Lossin
2025-09-07 23:33 ` Danilo Krummrich
2025-09-08 2:08 ` Boqun Feng
2025-09-08 8:27 ` Benno Lossin
2025-09-08 8:57 ` Danilo Krummrich
2025-09-08 19:38 ` Boqun Feng
2025-09-08 20:31 ` Danilo Krummrich
2025-09-10 10:12 ` Benno Lossin
2025-09-05 17:21 ` Boqun Feng
2025-09-05 18:38 ` Danilo Krummrich [this message]
2025-09-06 14:23 ` kernel test robot
2025-09-11 21:35 ` 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=DCL32RUQ6Z56.1ERY7JBK6O1J6@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@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).