rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: num: bounded: add safety comment for Bounded::__new
@ 2025-12-01  6:25 Hsiu Che Yu
  2025-12-01 10:12 ` Alice Ryhl
  2025-12-01 12:44 ` Miguel Ojeda
  0 siblings, 2 replies; 6+ messages in thread
From: Hsiu Che Yu @ 2025-12-01  6:25 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Hsiu Che Yu, Miguel Ojeda, Yury Norov, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel

The `__new` constructor only performs a bounds check and stores the
value in the wrapper type. It does not perform any unsafe memory
operations, so it does not need to be marked as `unsafe`.

Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://github.com/Rust-for-Linux/linux/issues/1211

Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
---
 rust/kernel/num/bounded.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
index f870080af8ac..cde1b8ba6880 100644
--- a/rust/kernel/num/bounded.rs
+++ b/rust/kernel/num/bounded.rs
@@ -284,6 +284,9 @@ impl<T, const N: u32> Bounded<T, N>
     ///
     /// The caller remains responsible for checking, either statically or dynamically, that `value`
     /// can be represented as a `T` using at most `N` bits.
+    ///
+    /// **Note**: This function is not marked as `unsafe` because it performs no memory-unsafe
+    /// operations itself.
     const fn __new(value: T) -> Self {
         // Enforce the type invariants.
         const {
-- 
2.43.0


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

end of thread, other threads:[~2025-12-01 16:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01  6:25 [PATCH] rust: num: bounded: add safety comment for Bounded::__new Hsiu Che Yu
2025-12-01 10:12 ` Alice Ryhl
2025-12-01 13:26   ` Hsiu Che Yu
2025-12-01 12:44 ` Miguel Ojeda
2025-12-01 13:35   ` Hsiu Che Yu
2025-12-01 16:05     ` Miguel Ojeda

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).