On Fri, May 01, 2026 at 11:19:39AM -0400, Steven Rostedt wrote:
> On Fri, 1 May 2026 22:40:17 +0800
> Qian-Yu Lin <[email protected]> wrote:
>
> > I propose using a compound literal in v2, which eliminates the local
> > variable entirely and requires no extra include:
> >
> > #define trace_printk(fmt, ...) \
> > do { \
> > if (sizeof((char[]) \
> > {__stringify((__VA_ARGS__))}) > 3) \
> > do_trace_printk(fmt, ##__VA_ARGS__); \
> > else \
> > trace_puts(fmt); \
> > } while (0)
> >
> > This fully eliminates the shadowing risk without any compile overhead.
>
> Have you tested to make sure a string with no arguments still produces the
> trace_puts() and one that has arguments calls do_trace_printk()?
>
> I'm fine with that one if it still works.
>
> -- Steve
Yes, I verified it with the preprocessor output. I created a minimal
test file:
// kernel/trace/test_trace_printk.c
#include <linux/trace_printk.h>
void test(void) {
trace_printk("no args\n");
trace_printk("with arg %d\n", 42);
}
Then ran make kernel/trace/test_trace_printk.i.
The no-args case has sizeof((char[]){"()"}) which is 3, so 3 > 3 is
false and it falls through to trace_bputs/trace_puts.
The args case has sizeof((char[]){"(42)"}) which is 5, so 5 > 3 is
true and it goes to trace_bprintk/trace_printk with the argument
42 correctly passed through.
Qian-Yu