Commit 09c3c911 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Miguel Ojeda
Browse files

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: cc84ef3b ("rust: bits: add support for bits/genmask macros")
Reviewed-by: default avatarDaniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20251208-io-build-assert-v3-4-98aded02c1ea@nvidia.com


Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent ac3c50b9
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ pub fn [<checked_bit_ $ty>](n: u32) -> Option<$ty> {
            ///
            /// This version is the default and should be used if `n` is known at
            /// compile time.
            #[inline]
            // Always inline to optimize out error path of `build_assert`.
            #[inline(always)]
            pub const fn [<bit_ $ty>](n: u32) -> $ty {
                build_assert!(n < <$ty>::BITS);
                (1 as $ty) << n
@@ -75,7 +76,8 @@ pub fn [<genmask_checked_ $ty>](range: RangeInclusive<u32>) -> Option<$ty> {
            /// This version is the default and should be used if the range is known
            /// at compile time.
            $(#[$genmask_ex])*
            #[inline]
            // Always inline to optimize out error path of `build_assert`.
            #[inline(always)]
            pub const fn [<genmask_ $ty>](range: RangeInclusive<u32>) -> $ty {
                let start = *range.start();
                let end = *range.end();