]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf machine: Propagate machine__init() error to callers
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 13 Jun 2026 16:46:29 +0000 (13:46 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 17 Jun 2026 12:21:03 +0000 (09:21 -0300)
commit8a4506595857356fcef9f7aad3506593e9fabbbc
treecd7ada019754c171d0d331d101bb2f340f778424
parentd669529868b355e1f10ff869539dc995cd25db3f
perf machine: Propagate machine__init() error to callers

machine__init() always returns 0 even when memory allocation fails,
because commit 81f981d7ec43ed93 ("perf machine: Free root_dir in
machine__init() error path") introduced 'int err = -ENOMEM' and an
error cleanup path but left the final 'return 0' instead of
'return err'.

Fix by returning err, check the return value in __machine__new_host()
which was ignoring it, and change machines__init() from void to int so
it too can propagate the error to perf_session__new(), aslr_tool__init()
and test callers.

The error cleanup also used zfree(&machine->kmaps), but kmaps is a
refcounted maps structure — use maps__zput() to properly drop the
reference, matching machine__exit().

Move dsos__init() and threads__init() before the first fallible
allocation (maps__new) so that machine__exit() is safe to call on
any machine struct that machine__init() touched, even on early failure.

Fixes: 81f981d7ec43ed93 ("perf machine: Free root_dir in machine__init() error path")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/hists_cumulate.c
tools/perf/tests/hists_filter.c
tools/perf/tests/hists_link.c
tools/perf/tests/hists_output.c
tools/perf/tests/kallsyms-split.c
tools/perf/tests/thread-maps-share.c
tools/perf/tests/vmlinux-kallsyms.c
tools/perf/util/aslr.c
tools/perf/util/machine.c
tools/perf/util/machine.h
tools/perf/util/session.c