rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Navaneeth K <knavaneeth786@gmail.com>
To: ojeda@kernel.org, alex.gaynor@gmail.com
Cc: wedsonaf@gmail.com, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Navaneeth K <knavaneeth786@gmail.com>
Subject: [PATCH 2/2] rust: kernel: document safety for as_str_unchecked
Date: Sat, 22 Nov 2025 19:09:08 +0000	[thread overview]
Message-ID: <20251122190908.259929-3-knavaneeth786@gmail.com> (raw)
In-Reply-To: <20251122190908.259929-1-knavaneeth786@gmail.com>

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


      parent reply	other threads:[~2025-11-22 19:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251122190908.259929-3-knavaneeth786@gmail.com \
    --to=knavaneeth786@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).