From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="FS3ez3D8" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB6FA119 for ; Sat, 25 Nov 2023 04:51:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1700916693; x=1701175893; bh=5cwlw0HuMDDbZgo/K1At3+rO2e/15vaUqRXcq/BERzM=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=FS3ez3D8nDEmE+MRVnSjRM9nxTRr8v9kzeCCfjs7zZYj3YGzeyW4G2sPVZfmcU2hW CDdNb/nAxVfWR0uZ5lu30LwUdKIGM1ZzwAkldj471VMulFRmoTbdgN6qS2QSrYELEU QSfRsiwmR0lL4KrlQTAsZA0hZ5BXW4cWJFaRDPkD0E22LxezynuZqdKe2JJiD2huVr HOfNXZciWch/10Vm/Bu2ZLszU5hX6vGLGtAu8nBEomhkCbmT/PkPOVNrssLXl8I30g ++D2QaElRThHrNYAUL9TUrIYwdqTGST66IGS560BcK817bPYxTnr7Jw0KOdZO2/mYq 2hX2k5YW7GDhw== Date: Sat, 25 Nov 2023 12:51:23 +0000 To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Tejun Heo From: Benno Lossin Cc: Wedson Almeida Filho , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work` Message-ID: <20231125125024.1235933-3-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The previous two patches made it possible to add `#[pin_data]` to structs with default values to const generic paramters. This patch makes `Work` use `#[pin_data]` and removes an invocation of `pin_init_from_closure`. This function is intended as a low level manual escape hatch, so it is better to rely on the `pin_init!` macro. Signed-off-by: Benno Lossin --- @Miguel: This patch is based on v6.7-rc2, because `workqueue.rs` has yet to land in rust-next. The first two patches also apply to rust-next. rust/kernel/workqueue.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index b67fb1ba168e..15bcfdb1ed33 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -334,8 +334,10 @@ pub trait WorkItem { /// Wraps the kernel's C `struct work_struct`. /// /// This is a helper type used to associate a `work_struct` with the [`Wor= kItem`] that uses it. +#[pin_data] #[repr(transparent)] pub struct Work { + #[pin] work: Opaque, _inner: PhantomData, } @@ -357,21 +359,22 @@ pub fn new(name: &'static CStr, key: &'static LockCla= ssKey) -> impl PinInit, { - // SAFETY: The `WorkItemPointer` implementation promises that `run= ` can be used as the work - // item function. - unsafe { - kernel::init::pin_init_from_closure(move |slot| { - let slot =3D Self::raw_get(slot); - bindings::init_work_with_key( - slot, - Some(T::Pointer::run), - false, - name.as_char_ptr(), - key.as_ptr(), - ); - Ok(()) - }) - } + pin_init!(Self { + work: Opaque::ffi_init(|slot| { + // SAFETY: The `WorkItemPointer` implementation promises t= hat `run` can be used as + // the work item function. + unsafe { + bindings::init_work_with_key( + slot, + Some(T::Pointer::run), + false, + name.as_char_ptr(), + key.as_ptr(), + ) + } + }), + _inner: PhantomData, + }) } =20 /// Get a pointer to the inner `work_struct`. --=20 2.40.1