Re: [PATCH v1 5/7] perf inject: Use perf_tool__init() for --vm-time-correlation

From: Aaron Tomlin

Date: Tue Oct 27 2026 - 16:43:30 EST


On Sun, Oct 25, 2026 at 03:03:47PM -0700, Ian Rogers wrote:
> When cmd_inject() was converted to use perf_tool__init() in commit
> a37c0436f379 ("perf inject: Use perf_tool__init()"), the
> --vm-time-correlation branch in __cmd_inject() still called
> memset(&inject->tool, 0, sizeof(inject->tool)) to clear the default
> repipe callbacks. Zeroing out the struct overwrites all default stub
> handlers set by perf_tool__init() with NULL, causing a NULL function
> pointer dereference if any other event type is encountered.
>
> Use perf_tool__init(&inject->tool, /*ordered_events=*/true) instead of
> memset() so that un-overridden callbacks retain their default stub
> handlers.
>
> Fixes: a37c0436f379 ("perf inject: Use perf_tool__init()")
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---
> tools/perf/builtin-inject.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index ce7562fc788c..c30f5aaabf4c 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -2464,12 +2464,11 @@ static int __cmd_inject(struct perf_inject *inject)
> }
> } else if (inject->itrace_synth_opts.vm_time_correlation) {
> session->itrace_synth_opts = &inject->itrace_synth_opts;
> - memset(&inject->tool, 0, sizeof(inject->tool));
> + perf_tool__init(&inject->tool, /*ordered_events=*/true);
> inject->tool.id_index = perf_event__process_id_index;
> inject->tool.auxtrace_info = perf_event__process_auxtrace_info;
> inject->tool.auxtrace = perf_event__process_auxtrace;
> inject->tool.auxtrace_error = perf_event__process_auxtrace_error;
> - inject->tool.ordered_events = true;
> inject->tool.ordering_requires_timestamps = true;
> } else if (inject->itrace_synth_opts.set) {
> session->itrace_synth_opts = &inject->itrace_synth_opts;
> --
> 2.56.0.307.g5fe7bd680c-goog
>

Reviewed-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>

--
Aaron Tomlin