tracing: Use strcmp() in __assign_str() WARN_ON() check
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 12 Mar 2024 15:30:02 +0000 (11:30 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 18 Mar 2024 14:33:06 +0000 (10:33 -0400)
commitb1afefa62ca9d77c8b1d386c3512fb4f21cb7db1
treec68e1ace997379b6156e07b651b6da1a8544c238
parent1b273124107cc8b9dd52228eba701efa516a3d92
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 51270d573a8d ("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/20240312113002.00031668@gandalf.local.home
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202402292111.KIdExylU-lkp@intel.com/
Fixes: 433e1d88a3be ("tracing: Add warning if string in __assign_str() does not match __string()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/trace/stages/stage6_event_callback.h