[PATCH] perf trace: propagate evsel__set_filter() error in trace__expand_filter()
From: Gu Bin
Date: Thu Nov 12 2026 - 03:24:16 EST
At the end of trace__expand_filter(), the return value of
evsel__set_filter() is ignored. When the strdup() inside fails with
-ENOMEM, the function returns 0 anyway, leaving evsel->filter holding
the unexpanded filter, which still contains the symbolic constants the
loop meant to resolve. The failure then surfaces later and indirectly:
evlist__apply_filters() passes the unexpanded string to the tracepoint
filter parser, which rejects the symbolic name, so perf trace fails to
start with a filter syntax error whose real cause is the missed
allocation.
Propagate the error so the -ENOMEM is reported at the source and the
caller fails immediately.
Fixes: 90df0249c2ea ("perf trace: Expand strings in filters to integers")
Signed-off-by: Gu Bin <gubin@xxxxxxxxxxxxxxxxxxxx>
---
tools/perf/builtin-trace.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Found by the sashiko review of the fix to the asprintf() failure path
in the same function ([PATCH] perf trace: guard free(new_filter) to
avoid double-free on OOM), which flagged the unchecked return value of
evsel__set_filter() as a related pre-existing issue:
https://sashiko.dev/#/bug/linux-cbf4bb01-a981-47dc-b440-68e5c9c3e81c
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 4094141461f91..ce1a7352ea9dd 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -4704,9 +4704,13 @@ static int trace__expand_filter(struct trace *trace, struct evsel *evsel)
}
if (new_filter != evsel->filter) {
+ int err;
+
pr_debug("New filter for %s: %s\n", evsel->name, new_filter);
- evsel__set_filter(evsel, new_filter);
+ err = evsel__set_filter(evsel, new_filter);
free(new_filter);
+ if (err)
+ return err;
}
return 0;
--
2.50.1.windows.1