From: Qian-Yu Lin <tiffany019230@gmail.com>
To: rostedt@goodmis.org, mhiramat@kernel.org
Cc: mathieu.desnoyers@efficios.com, david.laight.linux@gmail.com,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Qian-Yu Lin <tiffany019230@gmail.com>
Subject: [PATCH v2] trace_printk: replace ___STR with compound literal
Date: Sat, 2 May 2026 00:28:26 +0800 [thread overview]
Message-ID: <20260501162826.20582-1-tiffany019230@gmail.com> (raw)
In-Reply-To: <20260429165707.7020-1-tiffany019230@gmail.com>
The macro trace_printk() uses a hardcoded identifier ___STR
within a statement expression, which can lead to variable name
shadowing if a caller happens to use the same name in its scope.
Replace the hardcoded identifier with a compound literal, which
eliminates the local variable entirely and removes any shadowing
risk without requiring an extra include or helper macro.
Since trace_printk() is never nested, __UNIQUE_ID() provides no
practical benefit here. The compound literal approach is simpler
and has no compile time overhead, unlike the v1 approach which
added #include <linux/compiler.h>.
Signed-off-by: Qian-Yu Lin <tiffany019230@gmail.com>
---
include/linux/trace_printk.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/trace_printk.h b/include/linux/trace_printk.h
index 2670ec7f4262..7a4f6711834f 100644
--- a/include/linux/trace_printk.h
+++ b/include/linux/trace_printk.h
@@ -86,8 +86,7 @@ do { \
#define trace_printk(fmt, ...) \
do { \
- char _______STR[] = __stringify((__VA_ARGS__)); \
- if (sizeof(_______STR) > 3) \
+ if (sizeof((char[]){__stringify((__VA_ARGS__))}) > 3) \
do_trace_printk(fmt, ##__VA_ARGS__); \
else \
trace_puts(fmt); \
--
2.43.0
next prev parent reply other threads:[~2026-05-01 16:30 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
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 ` Qian-Yu Lin [this message]
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=20260501162826.20582-1-tiffany019230@gmail.com \
--to=tiffany019230@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--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