Message ID | 20250303-export-macro-v3-4-41fbad85a27f@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Check Rust signatures at compile time | expand |
On Mon, Mar 03, 2025 at 08:45:15AM +0000, Alice Ryhl wrote: > 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. ... > extern bool no_hash_pointers; > int no_hash_pointers_enable(char *str); > > +/* Used for Rust formatting ('%pA'). */ In case you need a new version, please drop a period at the end as this is the style used in the sprintf.h already. > +char *rust_fmt_argument(char *buf, char *end, const void *ptr);
On Mon, Mar 3, 2025 at 10:46 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Mar 03, 2025 at 08:45:15AM +0000, Alice Ryhl wrote: > > 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. > > ... > > > extern bool no_hash_pointers; > > int no_hash_pointers_enable(char *str); > > > > +/* Used for Rust formatting ('%pA'). */ > > In case you need a new version, please drop a period at the end as this is the > style used in the sprintf.h already. Sure, I will remove the period if I send a new version. Alice
On Mon 2025-03-03 08:45:15, Alice Ryhl wrote: > 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> Best Regards, Petr
diff --git a/include/linux/sprintf.h b/include/linux/sprintf.h index 33dcbec71925..029ad83efd74 100644 --- a/include/linux/sprintf.h +++ b/include/linux/sprintf.h @@ -24,4 +24,7 @@ __scanf(2, 0) int vsscanf(const char *, const char *, va_list); extern bool no_hash_pointers; int no_hash_pointers_enable(char *str); +/* Used for Rust formatting ('%pA'). */ +char *rust_fmt_argument(char *buf, char *end, const void *ptr); + #endif /* _LINUX_KERNEL_SPRINTF_H */ diff --git a/lib/vsprintf.c b/lib/vsprintf.c index a8ac4c4fffcf..1da61c3e011f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2284,9 +2284,6 @@ int __init no_hash_pointers_enable(char *str) } early_param("no_hash_pointers", no_hash_pointers_enable); -/* Used for Rust formatting ('%pA'). */ -char *rust_fmt_argument(char *buf, char *end, const void *ptr); - /* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index 61ee36c5e5f5..cf4714242e14 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -8,13 +8,14 @@ use crate::{ ffi::{c_char, c_void}, + prelude::*, str::RawFormatter, }; use core::fmt; // Called from `vsprintf` with format specifier `%pA`. #[expect(clippy::missing_safety_doc)] -#[no_mangle] +#[export] unsafe extern "C" fn rust_fmt_argument( buf: *mut c_char, end: *mut c_char,