* [PATCH] tracing/synthetic: avoid comparing string against NULL
@ 2026-10-13 20:53 Arnd Bergmann
0 siblings, 0 replies; only message in thread
From: Arnd Bergmann @ 2026-10-13 20:53 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Arnd Bergmann, Mathieu Desnoyers, Yu Peng, Thomas Gleixner,
Thomas Weißschuh (Schneider Electric), Namhyung Kim,
linux-kernel, linux-trace-kernel
From: Arnd Bergmann <arnd@arndb.de>
gcc-10 warns about passing a NULL argument into __synth_event_add_val(),
which uses it in an unchecked strcmp():
In function '__synth_event_add_val',
inlined from 'synth_event_add_next_val' at kernel/trace/trace_events_synth.c:2162:9:
kernel/trace/trace_events_synth.c:2076:8: error: argument 2 null where non-null expected [-Werror=nonnull]
2076 | if (strcmp(field->name, field_name) == 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/string.h:65,
from kernel/trace/trace_events_synth.c:8:
kernel/trace/trace_events_synth.c: In function 'synth_event_add_next_val':
arch/s390/include/asm/string.h:39:5: note: in a call to function 'strcmp' declared here
39 | int strcmp(const char *s1, const char *s2);
| ^~~~~~
The code is actually correct here, as the trace_state->add_name
does check for it, but this is hard for the compiler to prove.
Avoid the problem by repeating the check where the compiler
sees it.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
kernel/trace/trace_events_synth.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index dc15658a887c..c1287ca95aff 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -2073,7 +2073,8 @@ static int __synth_event_add_val(const char *field_name, u64 val,
if (trace_state->add_name) {
for (i = 0; i < event->n_fields; i++) {
field = event->fields[i];
- if (strcmp(field->name, field_name) == 0)
+ if (!field_name ||
+ strcmp(field->name, field_name) == 0)
break;
}
if (!field) {
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-13 20:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 20:53 [PATCH] tracing/synthetic: avoid comparing string against NULL Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox