[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251122190908.259929-3-knavaneeth786@gmail.com>
Date: Sat, 22 Nov 2025 19:09:08 +0000
From: Navaneeth K <knavaneeth786@...il.com>
To: ojeda@...nel.org,
alex.gaynor@...il.com
Cc: wedsonaf@...il.com,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
Navaneeth K <knavaneeth786@...il.com>
Subject: [PATCH 2/2] rust: kernel: document safety for as_str_unchecked
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@...il.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
Powered by blists - more mailing lists