[PATCH] rust: print: document safety of printing functions

Mohamed Osama posted 1 patch 2 weeks, 2 days ago
rust/kernel/print.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] rust: print: document safety of printing functions
Posted by Mohamed Osama 2 weeks, 2 days ago
Signed-off-by: Mohamed Osama <mohamed.osama189110@gmail.com>
---
 rust/kernel/print.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 0d62beeedca5..def6ef5a1dec 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -29,7 +29,8 @@
     use fmt::Write;
     // 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: TODO.
+    // SAFETY: `ptr` is provided by the `%pA` formatting path and points to the
+    // `fmt::Arguments` passed to `_printk`.
     let _ = w.write_fmt(unsafe { *ptr.cast::<fmt::Arguments<'_>>() });
     w.pos().cast()
 }
@@ -109,7 +110,8 @@ pub unsafe fn call_printk(
 ) {
     // `_printk` does not seem to fail in any path.
     #[cfg(CONFIG_PRINTK)]
-    // SAFETY: TODO.
+    // SAFETY: `format_string` is one of the fixed format strings, `module_name` is
+    // null-terminated, and the `%pA` argument is a pointer to the valid `args`.
     unsafe {
         bindings::_printk(
             format_string.as_ptr(),
-- 
2.43.0
Re: [PATCH] rust: print: document safety of printing functions
Posted by Miguel Ojeda 2 weeks, 2 days ago
On Tue, Sep 8, 2026 at 10:38 PM Mohamed Osama
<mohamed.osama189110@gmail.com> wrote:
>
> Signed-off-by: Mohamed Osama <mohamed.osama189110@gmail.com>

Welcome and thanks for the patch!

The kernel requires a commit message.

In addition, please see (and maybe help review!) previous attempts:

  https://lore.kernel.org/rust-for-linux/20260729175305.723486-1-cianmcguire167@gmail.com/

Finally, the commit message should have the right tags, and Cc all the
maintainers and reviewers of the `RUST` subsystem from the
`MAINTAINERS` file.

Cheers,
Miguel