From: Riccardo <riccioadami@gmail.com>
To: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Riccardo Adami <riccioadami@gmail.com>
Subject: [PATCH] rust: document safety requirements for fmt::Arguments dereference
Date: Sat, 20 Dec 2025 10:14:01 +0000 [thread overview]
Message-ID: <20251220101401.25361-1-riccioadami@gmail.com> (raw)
From: Riccardo Adami <riccioadami@gmail.com>
This patch documents the safety requirements for dereferencing
`fmt::Arguments` in the kernel's `vsnprintf` formatting path. This
clarifies why it is safe to perform the unsafe dereference in
`rust_fmt_argument` and helps future maintainers understand the
invariants, reducing the risk of incorrect modifications.
---
rust/kernel/print.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 899bed9c08fd..5f54be97a6a0 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -25,10 +25,10 @@
// SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`.
let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) };
//SAFETY: `ptr` is provided by the kernel formatting path for the `%pA`
-// specifier during `vsnprintf` processing and always points to a valid
-// `fmt::Arguments` value created by the caller. The value lives at least
-// for the duration of this call and is only read here. It is not stored
-// or accessed after returning, so dereferencing it is safe.
+ // specifier during `vsnprintf` processing and always points to a valid
+ // `fmt::Arguments` value created by the caller. The value lives at least
+ // for the duration of this call and is only read here. It is not stored
+ // or accessed after returning, so dereferencing it is safe.
let _ = w.write_fmt(unsafe { *ptr.cast::<fmt::Arguments<'_>>() });
w.pos().cast()
--
2.52.0
next reply other threads:[~2025-12-20 10:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-20 10:14 Riccardo [this message]
2025-12-20 10:33 ` [PATCH] rust: document safety requirements for fmt::Arguments dereference Greg KH
-- strict thread matches above, loose matches on Subject: below --
2025-12-20 13:00 Riccardo
2025-12-20 13:26 ` Dirk Behme
2025-12-20 9:43 Riccardo
2025-12-20 9:55 ` Greg KH
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=20251220101401.25361-1-riccioadami@gmail.com \
--to=riccioadami@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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