Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: bits: always inline functions using build_assert with arguments

`build_assert` relies on the compiler to optimize out its error path.
Functions using it with its arguments must thus always be inlined,
otherwise the error path of `build_assert` might not be optimized out,
triggering a build error.

Cc: stable@vger.kernel.org
Fixes: cc84ef3b88f4 ("rust: bits: add support for bits/genmask macros")
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20251208-io-build-assert-v3-4-98aded02c1ea@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Alexandre Courbot and committed by
Miguel Ojeda
09c3c911 ac3c50b9

+4 -2
+4 -2
rust/kernel/bits.rs
··· 27 27 /// 28 28 /// This version is the default and should be used if `n` is known at 29 29 /// compile time. 30 - #[inline] 30 + // Always inline to optimize out error path of `build_assert`. 31 + #[inline(always)] 31 32 pub const fn [<bit_ $ty>](n: u32) -> $ty { 32 33 build_assert!(n < <$ty>::BITS); 33 34 (1 as $ty) << n ··· 76 75 /// This version is the default and should be used if the range is known 77 76 /// at compile time. 78 77 $(#[$genmask_ex])* 79 - #[inline] 78 + // Always inline to optimize out error path of `build_assert`. 79 + #[inline(always)] 80 80 pub const fn [<genmask_ $ty>](range: RangeInclusive<u32>) -> $ty { 81 81 let start = *range.start(); 82 82 let end = *range.end();