[PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk

From: Ali Zain

Date: Fri Feb 13 2026 - 00:31:47 EST


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@xxxxxxxxx>
---
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