rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work`
@ 2023-11-25 12:51 Benno Lossin
  2023-11-25 14:35 ` Alice Ryhl
  0 siblings, 1 reply; 3+ messages in thread
From: Benno Lossin @ 2023-11-25 12:51 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Martin Rodriguez Reboredo, Tejun Heo
  Cc: Wedson Almeida Filho, rust-for-linux, linux-kernel

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 <benno.lossin@proton.me>
---

@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<const ID: u64 = 0> {
 /// Wraps the kernel's C `struct work_struct`.
 ///
 /// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
+#[pin_data]
 #[repr(transparent)]
 pub struct Work<T: ?Sized, const ID: u64 = 0> {
+    #[pin]
     work: Opaque<bindings::work_struct>,
     _inner: PhantomData<T>,
 }
@@ -357,21 +359,22 @@ pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl PinInit<Self
     where
         T: WorkItem<ID>,
     {
-        // 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 = 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 that `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,
+        })
     }
 
     /// Get a pointer to the inner `work_struct`.
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work`
  2023-11-25 12:51 [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work` Benno Lossin
@ 2023-11-25 14:35 ` Alice Ryhl
  2023-11-25 14:54   ` Benno Lossin
  0 siblings, 1 reply; 3+ messages in thread
From: Alice Ryhl @ 2023-11-25 14:35 UTC (permalink / raw)
  To: Benno Lossin
  Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Wedson Almeida Filho,
	Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
	Björn Roy Baron, Andreas Hindborg, Alice Ryhl,
	Martin Rodriguez Reboredo, Tejun Heo

On 11/25/23 13:51, Benno Lossin wrote:
> +        pin_init!(Self {
> +            work: Opaque::ffi_init(|slot| {

Surely there should be an <- here instead of the : character?

Alice

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work`
  2023-11-25 14:35 ` Alice Ryhl
@ 2023-11-25 14:54   ` Benno Lossin
  0 siblings, 0 replies; 3+ messages in thread
From: Benno Lossin @ 2023-11-25 14:54 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Wedson Almeida Filho,
	Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
	Björn Roy Baron, Andreas Hindborg, Alice Ryhl,
	Martin Rodriguez Reboredo, Tejun Heo

On 25.11.23 15:35, Alice Ryhl wrote:
> On 11/25/23 13:51, Benno Lossin wrote:
>> +        pin_init!(Self {
>> +            work: Opaque::ffi_init(|slot| {
> 
> Surely there should be an <- here instead of the : character?

You are absolutely correct. I did this so rustfmt would format it nicely. But
forgot to change it back.

-- 
Cheers,
Benno



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-25 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-25 12:51 [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work` Benno Lossin
2023-11-25 14:35 ` Alice Ryhl
2023-11-25 14:54   ` Benno Lossin

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).