[PATCH] rust: uaccess: mark UserSliceWriter method inline

From: Antonio Hickey
Date: Wed Mar 12 2025 - 22:51:36 EST


When you build the kernel using the llvm-19.1.4-rust-1.83.0-x86_64
toolchain provided by kernel.org with ARCH=x86_64, the following symbol
is generated:

$nm vmlinux | grep ' _R' | rustfilt | rg UserSliceWriter
ffffffff817c3390 T <kernel::uaccess::UserSliceWriter>::write_slice

However, this Rust symbol is a trivial wrapper around the function
copy_from_user. It doesn't make sense to go through a trivial wrapper
for this function, so mark it inline.

After applying this patch, the above command will produce no output.

Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: Antonio Hickey <contact@xxxxxxxxxxxxxxxxx>
---
rust/kernel/uaccess.rs | 1 +
1 file changed, 1 insertion(+)

diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 719b0a48ff55..c33ff33d4da2 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -322,6 +322,7 @@ pub fn is_empty(&self) -> bool {
/// Fails with [`EFAULT`] if the write happens on a bad address, or if the write goes out of
/// bounds of this [`UserSliceWriter`]. This call may modify the associated userspace slice even
/// if it returns an error.
+ #[inline]
pub fn write_slice(&mut self, data: &[u8]) -> Result {
let len = data.len();
let data_ptr = data.as_ptr().cast::<c_void>();
--
2.48.1