Re: [PATCH v1 1/2] perf sched: Avoid segv if tp_handler not set
From: Namhyung Kim
Date: Thu Apr 02 2026 - 22:42:57 EST
On Tue, Mar 31, 2026 at 10:59:52PM -0700, Ian Rogers wrote:
> On Thu, Mar 26, 2026 at 4:20 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > On Fri, Mar 20, 2026 at 11:14:47PM -0700, Ian Rogers wrote:
> > > Doing a `perf sched record` then `perf sched stats report` crashes as
> > > the tp_handler isn't set. Add extra checks that tp_handler is set
> > > before accessing through it.
> >
> > Oh.. unintended use case. :) Probably better to add a dummy handler
> > for `perf sched stats report`.
>
> Perhaps. I'd prefer to land the simpler change as-is.
Well.. I guess the dummy handler approach would be simpler and perform
better. :)
Thanks,
Namhyung
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d083e2bb770303a4..9fb5447f9014d026 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4955,6 +4955,7 @@ int cmd_sched(int argc, const char **argv)
.switch_event = replay_switch_event,
.fork_event = replay_fork_event,
};
+ struct trace_sched_handler stats_ops = {};
int ret;
perf_tool__init(&sched.tool, /*ordered_events=*/true);
@@ -5037,6 +5038,7 @@ int cmd_sched(int argc, const char **argv)
} else if (!strcmp(argv[0], "stats")) {
const char *const stats_subcommands[] = {"record", "report", NULL};
+ sched.tp_handler = &stats_ops;
argc = parse_options_subcommand(argc, argv, stats_options,
stats_subcommands,
stats_usage,