Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

print: use new #[export] macro for rust_fmt_argument

This moves the rust_fmt_argument function over to use the new #[export]
macro, which will verify at compile-time that the function signature
matches what is in the header file.

Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20250303-export-macro-v3-4-41fbad85a27f@google.com
[ Removed period as requested by Andy. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Alice Ryhl and committed by
Miguel Ojeda
92d2873b 44e333fe

+5 -4
+3
include/linux/sprintf.h
··· 24 24 extern bool no_hash_pointers; 25 25 int no_hash_pointers_enable(char *str); 26 26 27 + /* Used for Rust formatting ('%pA') */ 28 + char *rust_fmt_argument(char *buf, char *end, const void *ptr); 29 + 27 30 #endif /* _LINUX_KERNEL_SPRINTF_H */
-3
lib/vsprintf.c
··· 2284 2284 } 2285 2285 early_param("no_hash_pointers", no_hash_pointers_enable); 2286 2286 2287 - /* Used for Rust formatting ('%pA'). */ 2288 - char *rust_fmt_argument(char *buf, char *end, const void *ptr); 2289 - 2290 2287 /* 2291 2288 * Show a '%p' thing. A kernel extension is that the '%p' is followed 2292 2289 * by an extra set of alphanumeric characters that are extended format
+2 -1
rust/kernel/print.rs
··· 8 8 9 9 use crate::{ 10 10 ffi::{c_char, c_void}, 11 + prelude::*, 11 12 str::RawFormatter, 12 13 }; 13 14 use core::fmt; 14 15 15 16 // Called from `vsprintf` with format specifier `%pA`. 16 17 #[expect(clippy::missing_safety_doc)] 17 - #[no_mangle] 18 + #[export] 18 19 unsafe extern "C" fn rust_fmt_argument( 19 20 buf: *mut c_char, 20 21 end: *mut c_char,