Skip to content

Commit 4099db9

Browse files
committed
rust: ensure IoMem's build_assert! call is inlined
This increases chance that `build_assert!` call in `check_offset` is optimized away under lower optimization levels and avoid false positives. Signed-off-by: Gary Guo <[email protected]>
1 parent 165a7fa commit 4099db9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rust/kernel/io_mem.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ macro_rules! define_read {
6868
///
6969
/// If the offset is not known at compile time, the build will fail.
7070
$(#[$attr])*
71+
#[inline]
7172
pub fn $name(&self, offset: usize) -> $type_name {
7273
Self::check_offset::<$type_name>(offset);
7374
let ptr = self.ptr.wrapping_add(offset);
@@ -100,6 +101,7 @@ macro_rules! define_write {
100101
///
101102
/// If the offset is not known at compile time, the build will fail.
102103
$(#[$attr])*
104+
#[inline]
103105
pub fn $name(&self, value: $type_name, offset: usize) {
104106
Self::check_offset::<$type_name>(offset);
105107
let ptr = self.ptr.wrapping_add(offset);
@@ -164,6 +166,7 @@ impl<const SIZE: usize> IoMem<SIZE> {
164166
}
165167
}
166168

169+
#[inline]
167170
const fn offset_ok<T>(offset: usize) -> bool {
168171
let type_size = core::mem::size_of::<T>();
169172
if let Some(end) = offset.checked_add(type_size) {
@@ -183,6 +186,7 @@ impl<const SIZE: usize> IoMem<SIZE> {
183186
}
184187
}
185188

189+
#[inline]
186190
const fn check_offset<T>(offset: usize) {
187191
crate::build_assert!(Self::offset_ok::<T>(offset), "IoMem offset overflow");
188192
}

0 commit comments

Comments
 (0)