[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250616-borrow_impls-v4-5-36f9beb3fe6a@nvidia.com>
Date: Mon, 16 Jun 2025 12:34:09 +0900
From: Alexandre Courbot <acourbot@...dia.com>
To: Danilo Krummrich <dakr@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Alexandre Courbot <acourbot@...dia.com>
Subject: [PATCH v4 5/7] rust: str: use transmute in
`from_bytes_with_nul_unchecked_mut`
`from_bytes_with_nul_unchecked` also does this, so do the same for
symmetry. This was probably not done due to the unavailability of the
`const_mut_refs` feature at the time this code was introduced.
Signed-off-by: Alexandre Courbot <acourbot@...dia.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 2640a050847e64bfd18c127a5a83b93f01f036bc..28f2f359ab23e6a926e88913e3cc9f481aa86037 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -290,7 +290,7 @@ pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, CStrConvertError
#[inline]
pub const unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut CStr {
// SAFETY: Properties of `bytes` guaranteed by the safety precondition.
- unsafe { &mut *(bytes as *mut [u8] as *mut CStr) }
+ unsafe { core::mem::transmute(bytes) }
}
/// Returns a C pointer to the string.
--
2.49.0
Powered by blists - more mailing lists