Skip to content

Commit 09c3c91

Browse files
Gnurouojeda
authored andcommitted
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: cc84ef3 ("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>
1 parent ac3c50b commit 09c3c91

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

rust/kernel/bits.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ macro_rules! impl_bit_fn {
2727
///
2828
/// This version is the default and should be used if `n` is known at
2929
/// compile time.
30-
#[inline]
30+
// Always inline to optimize out error path of `build_assert`.
31+
#[inline(always)]
3132
pub const fn [<bit_ $ty>](n: u32) -> $ty {
3233
build_assert!(n < <$ty>::BITS);
3334
(1 as $ty) << n
@@ -75,7 +76,8 @@ macro_rules! impl_genmask_fn {
7576
/// This version is the default and should be used if the range is known
7677
/// at compile time.
7778
$(#[$genmask_ex])*
78-
#[inline]
79+
// Always inline to optimize out error path of `build_assert`.
80+
#[inline(always)]
7981
pub const fn [<genmask_ $ty>](range: RangeInclusive<u32>) -> $ty {
8082
let start = *range.start();
8183
let end = *range.end();

0 commit comments

Comments
 (0)