Skip to contentSkip to conversation

perf auxtrace: Avoid redundant NULL check in auxtrace_mmap_params__set_idx()

PATCH Applied Gautam Menghani 5 participants 5 messages Aug 4, 2025 – Sep 12, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf auxtrace: Avoid redundant NULL check in auxtrace_mmap_params__set_idx()

Since commit eead8a011477 ("libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer"), perf_thread_map__pid() can check for a NULL map and return -1 if idx is 0. Cleanup auxtrace_mmap_params__set_idx() and remove the redundant NULL check.

No functional change intended.

---
 tools/perf/util/auxtrace.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/auxtrace.c +1 -4
index ebd32f1b8f12..5e437133c753 100644
@@ -185,10 +185,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
 
 	if (per_cpu) {
 		mp->cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx);
-		if (evlist->core.threads)
-			mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
-		else
-			mp->tid = -1;
+		mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
 	} else {
 		mp->cpu.cpu = -1;
 		mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gautam Menghani

Since commit eead8a011477 ("libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer"), perf_thread_map__pid() can check for a NULL map and return -1 if idx is 0. Cleanup auxtrace_mmap_params__set_idx() and remove the redundant NULL check.

No functional change intended.

Quoted 20 lines
---
 tools/perf/util/auxtrace.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/auxtrace.c +1 -4
index ebd32f1b8f12..5e437133c753 100644
@@ -185,10 +185,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
 
 	if (per_cpu) {
 		mp->cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx);
-		if (evlist->core.threads)
-			mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
-		else
-			mp->tid = -1;
+		mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
 	} else {
 		mp->cpu.cpu = -1;
 		mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
maintainer Applied
#2 lore raw
Quoted 11 lines · Adrian Hunter
Quoted 8 lines · Gautam Menghani

Since commit eead8a011477 ("libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer"), perf_thread_map__pid() can check for a NULL map and return -1 if idx is 0. Cleanup auxtrace_mmap_params__set_idx() and remove the redundant NULL check.

No functional change intended.

Thanks, applied to perf-tools-next,

- Arnaldo

Quoted 20 lines
Quoted 20 lines
---
 tools/perf/util/auxtrace.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/auxtrace.c +1 -4
index ebd32f1b8f12..5e437133c753 100644
@@ -185,10 +185,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
 
 	if (per_cpu) {
 		mp->cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx);
-		if (evlist->core.threads)
-			mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
-		else
-			mp->tid = -1;
+		mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
 	} else {
 		mp->cpu.cpu = -1;
 		mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Gautam Menghani
Quoted 8 lines · Gautam Menghani

Since commit eead8a011477 ("libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer"), perf_thread_map__pid() can check for a NULL map and return -1 if idx is 0. Cleanup auxtrace_mmap_params__set_idx() and remove the redundant NULL check.

No functional change intended.

LGTM.

Regards,
Amit

Quoted 23 lines
---
 tools/perf/util/auxtrace.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/auxtrace.c +1 -4
index ebd32f1b8f12..5e437133c753 100644
@@ -185,10 +185,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
 
 	if (per_cpu) {
 		mp->cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx);
-		if (evlist->core.threads)
-			mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
-		else
-			mp->tid = -1;
+		mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
 	} else {
 		mp->cpu.cpu = -1;
 		mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#4 lore raw
In reply to Gautam Menghani
Quoted 18 lines · Gautam Menghani

Since commit eead8a011477 ("libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer"), perf_thread_map__pid() can check for a NULL map and return -1 if idx is 0. Cleanup auxtrace_mmap_params__set_idx() and remove the redundant NULL check.

No functional change intended.

---
  tools/perf/util/auxtrace.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/auxtrace.c +0 -0
index ebd32f1b8f12..5e437133c753 100644
@@ -185,10 +185,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
 

tools/perf/util/auxtrace.c void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, · line 191

Quoted 10 lines
tools/perf/util/auxtrace.c +1 -4
  	if (per_cpu) {
  		mp->cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx);
-		if (evlist->core.threads)
-			mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
-		else
-			mp->tid = -1;
+		mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
  	} else {
  		mp->cpu.cpu = -1;
  		mp->tid = perf_thread_map__pid(evlist->core.threads, idx);

LGTM.