Commit 246dc53f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'rust-fixes-6.2' of https://github.com/Rust-for-Linux/linux

Pull rust fix from Miguel Ojeda:

 - Avoid evaluating arguments in 'pr_*' macros in 'unsafe' blocks

* tag 'rust-fixes-6.2' of https://github.com/Rust-for-Linux/linux:
  rust: print: avoid evaluating arguments in `pr_*` macros in `unsafe` blocks
parents b2f31717 6618d69a
...@@ -142,17 +142,24 @@ pub fn call_printk_cont(args: fmt::Arguments<'_>) { ...@@ -142,17 +142,24 @@ pub fn call_printk_cont(args: fmt::Arguments<'_>) {
macro_rules! print_macro ( macro_rules! print_macro (
// The non-continuation cases (most of them, e.g. `INFO`). // The non-continuation cases (most of them, e.g. `INFO`).
($format_string:path, false, $($arg:tt)+) => ( ($format_string:path, false, $($arg:tt)+) => (
// SAFETY: This hidden macro should only be called by the documented // To remain sound, `arg`s must be expanded outside the `unsafe` block.
// printing macros which ensure the format string is one of the fixed // Typically one would use a `let` binding for that; however, `format_args!`
// ones. All `__LOG_PREFIX`s are null-terminated as they are generated // takes borrows on the arguments, but does not extend the scope of temporaries.
// by the `module!` proc macro or fixed values defined in a kernel // Therefore, a `match` expression is used to keep them around, since
// crate. // the scrutinee is kept until the end of the `match`.
unsafe { match format_args!($($arg)+) {
$crate::print::call_printk( // SAFETY: This hidden macro should only be called by the documented
&$format_string, // printing macros which ensure the format string is one of the fixed
crate::__LOG_PREFIX, // ones. All `__LOG_PREFIX`s are null-terminated as they are generated
format_args!($($arg)+), // by the `module!` proc macro or fixed values defined in a kernel
); // crate.
args => unsafe {
$crate::print::call_printk(
&$format_string,
crate::__LOG_PREFIX,
args,
);
}
} }
); );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment