mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ali Zain <alizainuimx@gmail.com>
To: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, ojeda@kernel.org,
	boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
	lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
	tmgross@umich.edu, dakr@kernel.org,
	Ali Zain <alizainuimx@gmail.com>
Subject: [PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk
Date: Fri, 13 Feb 2026 10:31:23 +0500	[thread overview]
Message-ID: <20260213053123.8869-1-alizainuimx@gmail.com> (raw)
In-Reply-To: <20260212125427.122362-1-alizainuimx@gmail.com>

Replace remaining "SAFETY: TODO" comments with proper explanations.

Document why the raw pointer cast to `fmt::Arguments` is valid
and clarify the invariants required when calling `_printk`
through FFI.

This does not change behaviour.

v2:
  - Fix rustfmt formatting issue reported by 0-day CI.
  - Remove extra blank line before unsafe block.

Signed-off-by: Ali Zain <alizainuimx@gmail.com>
---
 rust/kernel/list.rs  | 2 ++
 rust/kernel/print.rs | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index 0d8a201f2..65d33957e 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -589,6 +589,8 @@ pub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>> {
         //   or in this list (with the same `ID`).
         // - We hold `&mut self`, so there is no concurrent mutation of
         //   the link fields.
+        // - `T::view_links(item)` returns the embedded link fields for this
+        //   object, which remain valid for the lifetime of `item`.
 
         let mut item = unsafe { ListLinks::fields(T::view_links(item)) };
         // SAFETY: The user provided a reference, and reference are never dangling.
diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 2ae7b4ce9..c3edc0ab3 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -112,7 +112,6 @@ pub unsafe fn call_printk(
     // at compile time, a null-terminated module name, and a pointer to
     // `fmt::Arguments` obtained via `core::ptr::from_ref`. All pointers
     // are valid for the duration of the call and respect the C ABI.
-
     unsafe {
         bindings::_printk(
             format_string.as_ptr(),
-- 
2.53.0


       reply	other threads:[~2026-02-13  5:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260212125427.122362-1-alizainuimx@gmail.com>
2026-02-13  5:31 ` Ali Zain [this message]
2026-02-16 20:31   ` Miguel Ojeda

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=20260213053123.8869-1-alizainuimx@gmail.com \
    --to=alizainuimx@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --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

all inboxes | Powered by JetHome®