]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: build_assert: add instructions for use with function arguments
authorAlexandre Courbot <acourbot@nvidia.com>
Mon, 8 Dec 2025 02:46:59 +0000 (11:46 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 19 Jan 2026 00:13:22 +0000 (01:13 +0100)
commit1b18b37a2c30f6e6698205a06de393f7e626f5d2
tree253b465ff290256647b651e8331f447fc69bc35c
parent9fa7153c31a3e5fe578b83d23bc9f185fde115da
rust: build_assert: add instructions for use with function arguments

`build_assert` relies on the compiler to optimize out its error path,
lest build fails with the dreaded error:

    ERROR: modpost: "rust_build_error" [path/to/module.ko] undefined!

It has been observed that very trivial code performing I/O accesses
(sometimes even using an immediate value) would seemingly randomly fail
with this error whenever `CLIPPY=1` was set. The same behavior was also
observed until different, very similar conditions [1][2].

The cause appears to be that the failing function is eventually using
`build_assert` with its argument, but is only annotated with
`#[inline]`. This gives the compiler freedom to not inline the function,
which it notably did when Clippy was active, triggering the error.

The fix is to annotate functions passing their argument to
`build_assert` with `#[inline(always)]`, telling the compiler to be as
aggressive as possible with their inlining. This is also the correct
behavior as inlining is mandatory for correct behavior in these cases.

Add a paragraph instructing to annotate such functions with
`#[inline(always)]` in `build_assert`'s documentation, and split its
example to illustrate.

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-1-98aded02c1ea@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/build_assert.rs