Skip to contentSkip to conversation

perf stat: Fix error check for bpf_program__attach

PATCH Applied Namhyung Kim 2 participants 2 messages May 27, 2021 – May 28, 2021 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf stat: Fix error check for bpf_program__attach

It seems the bpf_program__attach() returns a negative error code instead of a NULL pointer in case of error.

Fixes 7fac83aaf2ee ("perf stat: Introduce 'bperf' to share hardware PMCs with BPF")
Cc Song Liu <[email protected]>
---
 tools/perf/util/bpf_counter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/bpf_counter.c +2 -2
index ddb52f748c8e..974f10e356f0 100644
@@ -451,10 +451,10 @@ static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
 		goto out;
 	}
 
-	err = -1;
 	link = bpf_program__attach(skel->progs.on_switch);
-	if (!link) {
+	if (IS_ERR(link)) {
 		pr_err("Failed to attach leader program\n");
+		err = PTR_ERR(link);
 		goto out;
 	}
 
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
maintainer Applied
#1 lore raw

Em Thu, May 27, 2021 at 03:00:52PM -0700, Namhyung Kim escreveu:

Quoted 2 lines

It seems the bpf_program__attach() returns a negative error code instead of a NULL pointer in case of error.

Thanks, applied.

- Arnaldo

Quoted 27 lines
Fixes 7fac83aaf2ee ("perf stat: Introduce 'bperf' to share hardware PMCs with BPF")
Cc Song Liu <[email protected]>
---
 tools/perf/util/bpf_counter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/bpf_counter.c +2 -2
index ddb52f748c8e..974f10e356f0 100644
@@ -451,10 +451,10 @@ static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
 		goto out;
 	}
 
-	err = -1;
 	link = bpf_program__attach(skel->progs.on_switch);
-	if (!link) {
+	if (IS_ERR(link)) {
 		pr_err("Failed to attach leader program\n");
+		err = PTR_ERR(link);
 		goto out;
 	}
 
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
Signature · 1 line
- Arnaldo