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="eWv5PSEi" Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78163EA; Wed, 13 Dec 2023 14:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1702505362; x=1702764562; bh=HEh8GOBW89PGEJ9xzMl86G8ozQum0hgJyYTbj8sFLEs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=eWv5PSEiLPvHNdz71xYJcidf281WJHTlXrjDyLIpSByBrLzTux4LrveZ/Prak6Zhk AT/apxLngUyyqoeALLk/T/FuxULzpAvqDcL0Ps1nhgXqUKUAjuPhg7O7rgOz9y2rqt lDgfZgJy2GQSRWFaZrJtjGiv8SYUaJ78W/Z0hrtsO+6X1UNYVlY7do9u0iDsZkGXTx UkvmN0EwUBZhS1+5C6Y3Dwdf5UHaruT1Kn7V9W2wED9QSl/Wv2s7e9qaLLzHYAkqgZ O5n1mUy/zbKPR4OaIt0cRx813c0TSlGJiHWIqOo+6b9vgXr+Y5X6cJtUdJuh8gbDZd 70Qk0nv/uTCig== Date: Wed, 13 Dec 2023 22:09:04 +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 v2 3/3] rust: workqueue: add `#[pin_data]` to `Work` Message-ID: <20231213220447.3613500-3-benno.lossin@proton.me> In-Reply-To: <20231213220447.3613500-1-benno.lossin@proton.me> References: <20231213220447.3613500-1-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]` on structs with default generic parameter values. 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 safe `pin_init!` macro. Signed-off-by: Benno Lossin --- v1 -> v2: - improve commit message wording - change `:` to `<-` in `pin_init!` invocation 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..4a9fb7d06d20 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.42.0