[PATCH v2 3/5] perf tools: Remove NULL check for maps__machine()

From: Namhyung Kim

Date: Mon Oct 19 2026 - 01:55:48 EST


Now maps should have a machine, let's get rid of checks for the return
value. There are already many places to assume it returns non-NULL,
so having this kind of check could give confusion that it can return
NULL (which is not true anymore).

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/dlfilter.c | 3 +--
tools/perf/util/event.c | 3 ---
tools/perf/util/map.c | 9 +++------
tools/perf/util/python.c | 2 +-
4 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
index e11e144af62bb979..7e179d1d84d78358 100644
--- a/tools/perf/util/dlfilter.c
+++ b/tools/perf/util/dlfilter.c
@@ -233,8 +233,7 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len)
if (thread__maps(al->thread)) {
struct machine *machine = maps__machine(thread__maps(al->thread));

- if (machine)
- perf_sample__fetch_insn(d->sample, al->thread, machine);
+ perf_sample__fetch_insn(d->sample, al->thread, machine);
}
}

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ea75816d126a14be..2f80e364659fea71 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -706,9 +706,6 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
al->cpumode = cpumode;
al->filtered = 0;

- if (machine == NULL)
- return NULL;
-
if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
al->level = 'k';
maps = machine__kernel_maps(machine);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 41cdddc987eee710..d5319ffa88a7477c 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -538,13 +538,10 @@ u64 map__rip_2objdump(const struct map *map, u64 rip)
*/
if (kmap && is_entry_trampoline(kmap->name) && kmap->kmaps) {
struct machine *machine = maps__machine(kmap->kmaps);
+ struct map *kernel_map = machine__kernel_map(machine);

- if (machine) {
- struct map *kernel_map = machine__kernel_map(machine);
-
- if (kernel_map)
- map = kernel_map;
- }
+ if (kernel_map)
+ map = kernel_map;
}

if (!dso__adjust_symbols(dso))
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 60dbe2dad5eb8073..42c587cd54a527a4 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -4536,7 +4536,7 @@ static PyObject *pyrf_call_return__new(struct call_return *cr)
if (cr->thread) {
struct maps *maps = thread__maps(cr->thread);

- pevent->machine_pid = maps && maps__machine(maps) ? maps__machine(maps)->pid : 0;
+ pevent->machine_pid = maps ? maps__machine(maps)->pid : 0;
pevent->pid = thread__pid(cr->thread);
pevent->tid = thread__tid(cr->thread);
} else {
--
2.56.0