Skip to content

Commit b1afefa

Browse files
committed
tracing: Use strcmp() in __assign_str() WARN_ON() check
The WARN_ON() check in __assign_str() to catch where the source variable to the macro doesn't match the source variable to __string() gives an error in clang: >> include/trace/events/sunrpc.h:703:4: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] 670 | __assign_str(progname, "unknown"); That's because the __assign_str() macro has: WARN_ON_ONCE((src) != __data_offsets.dst##_ptr_); Where "src" is a string literal. Clang warns when comparing a string literal directly as it is undefined to what the value of the literal is. Since this is still to make sure the same string that goes to __string() is the same as __assign_str(), for string literals do a test for that and then use strcmp() in those cases Note that this depends on commit 51270d5 ("tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string") being applied, as this was what found that bug. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Nathan Chancellor <[email protected]> Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Fixes: 433e1d8 ("tracing: Add warning if string in __assign_str() does not match __string()") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 1b27312 commit b1afefa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/trace/stages/stage6_event_callback.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
do { \
3636
char *__str__ = __get_str(dst); \
3737
int __len__ = __get_dynamic_array_len(dst) - 1; \
38-
WARN_ON_ONCE((src) != __data_offsets.dst##_ptr_); \
38+
WARN_ON_ONCE(__builtin_constant_p(src) ? \
39+
strcmp((src), __data_offsets.dst##_ptr_) : \
40+
(src) != __data_offsets.dst##_ptr_); \
3941
memcpy(__str__, __data_offsets.dst##_ptr_ ? : \
4042
EVENT_NULL_STR, __len__); \
4143
__str__[__len__] = '\0'; \

0 commit comments

Comments
 (0)