[PATCH] perf annotate: Return an error for --gtk with --show-nr-samples
From: Weidong Wang via B4 Relay
Date: Wed Dec 02 2026 - 21:24:07 EST
From: Weidong Wang <weidongw@xxxxxxxxxxxx>
cmd_annotate() rejects --show-nr-samples in --gtk mode by printing an
error and returning ret. At that point ret holds the successful result
of hists__init() and is not updated again, so it is 0 and perf annotate
exits with status 0 without doing anything.
Return -EINVAL instead, as the other option checks in the function do,
so the failure is visible to callers.
Found by a static analysis tool.
The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.
Fixes: 1ac39372e06f ("perf annotate stdio: Support --show-nr-samples option")
Signed-off-by: Weidong Wang <weidongw@xxxxxxxxxxxx>
---
Tested on x86_64 with perf built with GTK4=1, before and after this
patch: "perf annotate --gtk --show-nr-samples" prints the error and
exits with status 0 before, and with status 234 (-EINVAL) after.
Testing:
- checkpatch.pl --strict: no errors or warnings.
---
tools/perf/builtin-annotate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 65846110c309..f3041479a528 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -839,7 +839,7 @@ int cmd_annotate(int argc, const char **argv)
#ifdef HAVE_GTK4_SUPPORT
if (symbol_conf.show_nr_samples && annotate.use_gtk) {
pr_err("--show-nr-samples is not available in --gtk mode at this time\n");
- return ret;
+ return -EINVAL;
}
#endif
---
base-commit: 316fdb2d4ed172316923794f91dc9cd2b44bebfd
change-id: 20261202-kbug-l1942-6437c34d9282
Best regards,
--
Weidong Wang <weidongw@xxxxxxxxxxxx>