From: Qian-Yu Lin <tiffany019230@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, david.laight.linux@gmail.com,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] trace_printk: replace _______STR with __UNIQUE_ID(STR)
Date: Sat, 2 May 2026 00:17:50 +0800 [thread overview]
Message-ID: <afTSLgFwpYW1py36@nova> (raw)
In-Reply-To: <20260501111939.0536140a@gandalf.local.home>
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 <tiffany019230@gmail.com> 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
next prev parent reply other threads:[~2026-05-01 16:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 16:57 [PATCH] trace_printk: replace _______STR with __UNIQUE_ID(STR) Qian-Yu Lin
2026-04-29 17:42 ` Steven Rostedt
2026-04-29 21:47 ` David Laight
2026-05-01 14:51 ` Qian-Yu Lin
2026-05-01 14:40 ` Qian-Yu Lin
2026-05-01 15:19 ` Steven Rostedt
2026-05-01 16:17 ` Qian-Yu Lin [this message]
2026-05-01 16:21 ` Steven Rostedt
2026-05-01 21:13 ` David Laight
2026-05-02 7:37 ` Qian-Yu Lin
2026-05-01 16:28 ` [PATCH v2] trace_printk: replace ___STR with compound literal Qian-Yu Lin
2026-05-02 7:55 ` [PATCH v3] trace_printk: remove local variable for argument detection Qian-Yu Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afTSLgFwpYW1py36@nova \
--to=tiffany019230@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox