Files
linux/rust/kernel
Alexandre Courbot bc197e24a3 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:(<kernel::num::bounded::Bounded<u8, 1>>::from_expr) in archive vmlinux.a

      - Miguel ]

Fixes: 01e345e82e ("rust: num: add Bounded integer wrapping type")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202511210055.RUsFNku1-lkp@intel.com/
Suggested-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20251122-bounded_ints_fix-v1-1-1e07589d4955@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-11-23 22:49:55 +01:00
..
2025-10-20 04:04:23 +02:00
2025-08-21 21:09:48 +02:00
2025-10-20 04:04:23 +02:00
2025-07-23 02:05:58 +02:00
2025-10-17 13:02:22 +02:00
2025-07-23 02:05:58 +02:00
2025-10-22 07:15:19 +02:00
2025-10-17 00:56:20 +02:00
2025-10-20 04:04:23 +02:00
2025-08-13 17:40:28 +02:00
2025-09-06 13:27:20 +02:00
2025-08-21 21:09:48 +02:00
2025-11-17 22:56:23 +01:00
2025-10-22 07:14:47 +02:00
2025-07-21 01:16:35 +02:00
2025-08-21 16:58:07 +02:00
2025-11-16 21:56:57 +01:00
2024-11-04 16:21:44 -05:00