rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: kernel: add missing safety documentation
@ 2025-11-22 19:09 Navaneeth K
  2025-11-22 19:09 ` [PATCH 1/2] rust: kernel: document safety for rust_fmt_argument Navaneeth K
  2025-11-22 19:09 ` [PATCH 2/2] rust: kernel: document safety for as_str_unchecked Navaneeth K
  0 siblings, 2 replies; 3+ messages in thread
From: Navaneeth K @ 2025-11-22 19:09 UTC (permalink / raw)
  To: ojeda, alex.gaynor; +Cc: wedsonaf, rust-for-linux, linux-kernel, Navaneeth K

This series adds missing // SAFETY: comments to unsafe blocks in
the Rust kernel abstractions, replacing existing TODOs.

This aligns the code with the project's requirement that all
unsafe blocks must be documented with a safety rationale.

Navaneeth K (2):
  rust: kernel: document safety for rust_fmt_argument
  rust: kernel: document safety for as_str_unchecked

 rust/kernel/print.rs | 2 +-
 rust/kernel/str.rs   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] rust: kernel: document safety for rust_fmt_argument
  2025-11-22 19:09 [PATCH 0/2] rust: kernel: add missing safety documentation Navaneeth K
@ 2025-11-22 19:09 ` Navaneeth K
  2025-11-22 19:09 ` [PATCH 2/2] rust: kernel: document safety for as_str_unchecked Navaneeth K
  1 sibling, 0 replies; 3+ messages in thread
From: Navaneeth K @ 2025-11-22 19:09 UTC (permalink / raw)
  To: ojeda, alex.gaynor; +Cc: wedsonaf, rust-for-linux, linux-kernel, Navaneeth K

Add a proper // SAFETY: comment for the unsafe pointer dereference in
rust_fmt_argument. The comment explains that the caller guarantees
the pointer validity, satisfying the Rust-for-Linux safety documentation
requirements.

Signed-off-by: Navaneeth K <knavaneeth786@gmail.com>
---
 rust/kernel/print.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 2d743d78d220..49fa87dfbce8 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -24,7 +24,7 @@
     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: The caller guarantees that `ptr` points to a valid `fmt::Arguments`.
     let _ = w.write_fmt(unsafe { *ptr.cast::<fmt::Arguments<'_>>() });
     w.pos().cast()
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] rust: kernel: document safety for as_str_unchecked
  2025-11-22 19:09 [PATCH 0/2] rust: kernel: add missing safety documentation Navaneeth K
  2025-11-22 19:09 ` [PATCH 1/2] rust: kernel: document safety for rust_fmt_argument Navaneeth K
@ 2025-11-22 19:09 ` Navaneeth K
  1 sibling, 0 replies; 3+ messages in thread
From: Navaneeth K @ 2025-11-22 19:09 UTC (permalink / raw)
  To: ojeda, alex.gaynor; +Cc: wedsonaf, rust-for-linux, linux-kernel, Navaneeth K

Replace the TODO safety comment with a proper explanation.
The safety of from_utf8_unchecked relies on the caller guaranteeing
that the input bytes are valid UTF-8.

Signed-off-by: Navaneeth K <knavaneeth786@gmail.com>
---
 rust/kernel/str.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 5c74e5f77601..2801388c6bd1 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -385,7 +385,7 @@ pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> {
     /// ```
     #[inline]
     pub unsafe fn as_str_unchecked(&self) -> &str {
-        // SAFETY: TODO.
+        // SAFETY: The caller guarantees that the contents are valid UTF-8.
         unsafe { core::str::from_utf8_unchecked(self.as_bytes()) }
     }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-22 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-22 19:09 [PATCH 0/2] rust: kernel: add missing safety documentation Navaneeth K
2025-11-22 19:09 ` [PATCH 1/2] rust: kernel: document safety for rust_fmt_argument Navaneeth K
2025-11-22 19:09 ` [PATCH 2/2] rust: kernel: document safety for as_str_unchecked Navaneeth K

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).