Messages in this thread | | | Date | Fri, 18 Mar 2022 17:04:45 +0100 | From | Petr Mladek <> | Subject | Re: [PATCH v5 12/20] vsprintf: add new `%pA` format specifier |
| |
On Fri 2022-03-18 16:07:31, Andy Shevchenko wrote: > On Thu, Mar 17, 2022 at 07:10:00PM +0100, Miguel Ojeda wrote: > > From: Gary Guo <gary@garyguo.net> > > > > This patch adds a format specifier `%pA` to `vsprintf` which formats > > a pointer as `core::fmt::Arguments`. Doing so allows us to directly > > format to the internal buffer of `printf`, so we do not have to use > > a temporary buffer on the stack to pre-assemble the message on > > the Rust side. > > > > This specifier is intended only to be used from Rust and not for C, so > > `checkpatch.pl` is intentionally unchanged to catch any misuse. > > ... > > > + case 'A': > > + if (!IS_ENABLED(CONFIG_RUST)) { > > + WARN_ONCE(1, "Please remove %%pA from non-Rust code\n"); > > + return error_string(buf, end, "(%pA?)", spec); > > + } > > I'm wondering if the Big Scary Banner as trace_printk() does would be better > (in case we can tell that %pA is used in the code when RUST=n).
Good question!
The advantage of WARN_ONCE() is that it shows the stack so that it is easier to locate the caller.
On the other hand, WARN_ONCE() is a bit misused here. It should be used only in situations that might be potentially fatal. It might even cause panic() with "panic_on_warn" kernel parameter.
Well, I am not sure if it is worth huge effort. WARN_ONCE() is practical in this case because of the backtrace. We could always create something better if people hit it more frequently and it causes real life problems.
Best Regards, Petr
| |