Skip to content

Commit d6ff6e8

Browse files
Gnurouojeda
authored andcommitted
rust: sync: refcount: 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: bb38f35 ("rust: implement `kernel::sync::Refcount`") Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Acked-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251208-io-build-assert-v3-5-98aded02c1ea@nvidia.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 09c3c91 commit d6ff6e8

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

rust/kernel/sync/refcount.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl Refcount {
2323
/// Construct a new [`Refcount`] from an initial value.
2424
///
2525
/// The initial value should be non-saturated.
26-
#[inline]
26+
// Always inline to optimize out error path of `build_assert`.
27+
#[inline(always)]
2728
pub fn new(value: i32) -> Self {
2829
build_assert!(value >= 0, "initial value saturated");
2930
// SAFETY: There are no safety requirements for this FFI call.

0 commit comments

Comments
 (0)