Skip to contentSkip to conversation

rust: print: document safety of printing functions

PATCH In review Mohamed Osama 2 participants 2 messages Sep 8 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: print: document safety of printing functions

---
 rust/kernel/print.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/kernel/print.rs +4 -2
index 0d62beeedca5..def6ef5a1dec 100644
@@ -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(),
Signature · 1 line
2.43.0