From: Steven Rostedt <rostedt@goodmis.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: "Masami Hiramatsu" <mhiramat@kernel.org>,
"Arnd Bergmann" <arnd@arndb.de>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Yu Peng" <pengyu@kylinos.cn>,
"Thomas Gleixner" <tglx@kernel.org>,
"Thomas Weißschuh (Schneider Electric)"
<thomas.weissschuh@linutronix.de>,
"Namhyung Kim" <namhyung@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/synthetic: avoid comparing string against NULL
Date: Tue, 17 Nov 2026 10:08:56 -0500 [thread overview]
Message-ID: <20261117100856.40ec1f4f@gandalf.local.home> (raw)
In-Reply-To: <20261013205412.2579779-1-arnd@kernel.org>
On Tue, 13 Oct 2026 22:53:52 +0200
Arnd Bergmann <arnd@kernel.org> wrote:
> 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.
Yeah, but the compiler is being stupid here. It's not that difficult for it
to see it.
if (field_name) { <<-- checks field_name
if (trace_state->add_next) {
ret = -EINVAL;
goto out;
}
trace_state->add_name = true; <<-- set add_name
} else {
if (trace_state->add_name) { <<-- If field_name is NULL and add name is set, error out here
ret = -EINVAL;
goto out;
}
trace_state->add_next = true;
}
if (trace_state->disabled)
goto out;
event = trace_state->event;
if (trace_state->add_name) { <<-- Only get here if add_name is set (thus field_name is not NULL)
for (i = 0; i < event->n_fields; i++) {
field = event->fields[i];
if (strcmp(field->name, field_name) == 0) <<-- test field_name
break;
}
>
> 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)
I don't like making the code look worse to please something stupid the
compiler is doing.
-- Steve
> break;
> }
> if (!field) {
prev parent reply other threads:[~2026-11-17 15:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 20:53 Arnd Bergmann
2026-11-17 15:08 ` Steven Rostedt [this message]
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=20261117100856.40ec1f4f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=pengyu@kylinos.cn \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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
all inboxes | Powered by JetHome®