[PATCH v3 2/2] rust: uaccess: refactor to use `overflow_assert!`
From: Antonio Hickey
Date: Sat Jun 21 2025 - 19:03:51 EST
Using the `overflow_assert!` macro here adds documentation to
the intent of the assertion, and avoids local `#ifdefs`s by
encapsulating the conditional behavior to the macro itself.
Co-developed-by: Daniel Cote <danielstonecote@xxxxxxxxx>
Signed-off-by: Daniel Cote <danielstonecote@xxxxxxxxx>
Signed-off-by: Antonio Hickey <contact@xxxxxxxxxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1159
Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
---
rust/kernel/uaccess.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 635a03e0989f..452a5e0d76d2 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -9,6 +9,7 @@
bindings,
error::Result,
ffi::{c_char, c_void},
+ overflow_assert,
prelude::*,
transmute::{AsBytes, FromBytes},
};
@@ -394,8 +395,7 @@ fn raw_strncpy_from_user(dst: &mut [MaybeUninit<u8>], src: UserPtr) -> Result<us
return Err(Error::from_errno(res as i32));
}
- #[cfg(CONFIG_RUST_OVERFLOW_CHECKS)]
- assert!(res <= len);
+ overflow_assert!(res <= len);
// GUARANTEES: `strncpy_from_user` was successful, so `dst` has contents in accordance with the
// guarantees of this function.
--
2.50.0