Rust for Linux List
 help / color / mirror / Atom feed
From: Andrea Tontini <andreatontinidev@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
	"Tejun Heo" <tj@kernel.org>,
	"Andreas Hindborg (Samsung)" <nmi@metaspace.dk>
Cc: rust-for-linux@vger.kernel.org,
	 Andrea Tontini <andreatontinidev@gmail.com>
Subject: [PATCH] rust: workqueue: fix SAFETY comments in Pin<KBox<T>> run()
Date: Mon, 23 Nov 2026 23:26:53 +0100	[thread overview]
Message-ID: <20261123-rust-workqueue-safety-comment-v1-1-48e4f9b35c30@gmail.com> (raw)

The `WorkItemPointer` implementation for `Pin<KBox<T>>` was copied from
the `Arc<T>` implementation, and the SAFETY comments in its `run()`
function still claim that the pointer comes from `Arc::into_raw`.

However, the matching `RawWorkItem::__enqueue` implementation for
`Pin<KBox<T>>` obtains the pointer from `KBox::into_raw`, which is also
what makes the subsequent `KBox::from_raw` call sound.

Update the comments to reference the correct function. No functional
change.

This patch was prepared with the help of an AI coding assistant (Claude
Code), which found the mismatch and wrote the change; it was reviewed
and build-tested with CLIPPY=1 by the submitter.

Fixes: 47f0dbe8fdc2 ("rust: workqueue: implement `WorkItemPointer` for pointer types")
Signed-off-by: Andrea Tontini <andreatontinidev@gmail.com>
---
 rust/kernel/workqueue.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs
index a872f9fffb90..3815f08dfc0e 100644
--- a/rust/kernel/workqueue.rs
+++ b/rust/kernel/workqueue.rs
@@ -890,9 +890,9 @@ unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Pin<KBox<T>>
     unsafe extern "C" fn run(ptr: *mut bindings::work_struct) {
         // The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`.
         let ptr = ptr.cast::<Work<T, ID>>();
-        // SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`.
+        // SAFETY: This computes the pointer that `__enqueue` got from `KBox::into_raw`.
         let ptr = unsafe { T::work_container_of(ptr) };
-        // SAFETY: This pointer comes from `Arc::into_raw` and we've been given back ownership.
+        // SAFETY: This pointer comes from `KBox::into_raw` and we've been given back ownership.
         let boxed = unsafe { KBox::from_raw(ptr) };
         // SAFETY: The box was already pinned when it was enqueued.
         let pinned = unsafe { Pin::new_unchecked(boxed) };

---
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
change-id: 20261122-rust-workqueue-safety-comment-4bde8f258d52

Best regards,
--  
Andrea Tontini <andreatontinidev@gmail.com>


                 reply	other threads:[~2026-11-23 22:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261123-rust-workqueue-safety-comment-v1-1-48e4f9b35c30@gmail.com \
    --to=andreatontinidev@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=lossin@kernel.org \
    --cc=nmi@metaspace.dk \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tj@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=yakoyoku@gmail.com \
    /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