rust: io: 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: ce30d94e6855 ("rust: add `io::{Io, IoRaw}` base types")
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Timur Tabi <ttabi@nvidia.com>
Link: https://patch.msgid.link/20251208-io-build-assert-v3-2-98aded02c1ea@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by Alexandre Courbot and committed by Danilo Krummrich 33d19f62 0f61b186

+8 -3
+6 -3
rust/kernel/io.rs
··· 142 142 /// Bound checks are performed on compile time, hence if the offset is not known at compile 143 143 /// time, the build will fail. 144 144 $(#[$attr])* 145 - #[inline] 145 + // Always inline to optimize out error path of `io_addr_assert`. 146 + #[inline(always)] 146 147 pub fn $name(&self, offset: usize) -> $type_name { 147 148 let addr = self.io_addr_assert::<$type_name>(offset); 148 149 ··· 172 171 /// Bound checks are performed on compile time, hence if the offset is not known at compile 173 172 /// time, the build will fail. 174 173 $(#[$attr])* 175 - #[inline] 174 + // Always inline to optimize out error path of `io_addr_assert`. 175 + #[inline(always)] 176 176 pub fn $name(&self, value: $type_name, offset: usize) { 177 177 let addr = self.io_addr_assert::<$type_name>(offset); 178 178 ··· 241 239 self.addr().checked_add(offset).ok_or(EINVAL) 242 240 } 243 241 244 - #[inline] 242 + // Always inline to optimize out error path of `build_assert`. 243 + #[inline(always)] 245 244 fn io_addr_assert<U>(&self, offset: usize) -> usize { 246 245 build_assert!(Self::offset_valid::<U>(offset, SIZE)); 247 246
+2
rust/kernel/io/resource.rs
··· 226 226 /// Resource represents a memory region that must be ioremaped using `ioremap_np`. 227 227 pub const IORESOURCE_MEM_NONPOSTED: Flags = Flags::new(bindings::IORESOURCE_MEM_NONPOSTED); 228 228 229 + // Always inline to optimize out error path of `build_assert`. 230 + #[inline(always)] 229 231 const fn new(value: u32) -> Self { 230 232 crate::build_assert!(value as u64 <= c_ulong::MAX as u64); 231 233 Flags(value as c_ulong)