From: Alexandre Courbot Date: Sat, 22 Nov 2025 04:00:49 +0000 (+0900) Subject: rust: num: bounded: Always inline fits_within and from_expr X-Git-Tag: v6.19-rc1~175^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc197e24a3acd13dd0b7b07c1448c5c225946546;p=thirdparty%2Flinux.git rust: num: bounded: Always inline fits_within and from_expr `from_expr` relies on `build_assert` to infer that the passed expression fits the type's boundaries at build time. That inference can only be successful its code (and that of `fits_within`, which performs the check) is inlined, as a dedicated function would need to work with a variable and cannot verify that property. While inlining happens as expected in most cases, it is not guaranteed. In particular, kernel options that optimize for size like `CONFIG_CC_OPTIMIZE_FOR_SIZE` can result in `from_expr` not being inlined. Add `#[inline(always)]` attributes to both `fits_within` and `from_expr` to make the compiler inline these functions more aggressively, as it does not make sense to use them non-inlined anyway. [ For reference, the errors look like: ld.lld: error: undefined symbol: rust_build_error >>> referenced by build_assert.rs:83 (rust/kernel/build_assert.rs:83) >>> rust/doctests_kernel_generated.o:(>::from_expr) in archive vmlinux.a - Miguel ] Fixes: 01e345e82ec3 ("rust: num: add Bounded integer wrapping type") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202511210055.RUsFNku1-lkp@intel.com/ Suggested-by: Gary Guo Signed-off-by: Alexandre Courbot Link: https://patch.msgid.link/20251122-bounded_ints_fix-v1-1-1e07589d4955@nvidia.com Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs index 18e45bf6f84bd..92c41b2eb7606 100644 --- a/rust/kernel/num/bounded.rs +++ b/rust/kernel/num/bounded.rs @@ -35,6 +35,7 @@ macro_rules! fits_within { } /// Returns `true` if `value` can be represented with at most `N` bits in a `T`. +#[inline(always)] fn fits_within(value: T, num_bits: u32) -> bool { fits_within!(value, T, num_bits) } @@ -362,6 +363,7 @@ where /// assert_eq!(Bounded::::from_expr(1).get(), 1); /// assert_eq!(Bounded::::from_expr(0xff).get(), 0xff); /// ``` + #[inline(always)] pub fn from_expr(expr: T) -> Self { crate::build_assert!( fits_within(expr, N),