lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220413093123.2538001-1-lv.ruyi@zte.com.cn>
Date:   Wed, 13 Apr 2022 09:31:23 +0000
From:   cgel.zte@...il.com
To:     shuah@...nel.org, ast@...nel.org, daniel@...earbox.net
Cc:     andrii@...nel.org, kafai@...com, songliubraving@...com, yhs@...com,
        john.fastabend@...il.com, kpsingh@...nel.org, joannekoong@...com,
        lv.ruyi@....com.cn, toke@...hat.com, houtao1@...wei.com,
        linux-kselftest@...r.kernel.org, netdev@...r.kernel.org,
        bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
        Zeal Robot <zealci@....com.cn>
Subject: [PATCH] bpf/benchs: fix error check return value of bpf_program__attach()

From: Lv Ruyi <lv.ruyi@....com.cn>

bpf_program__attach() returns error ptr when it fails, so we should use
IS_ERR() to check it in error handling path. The patch fix all the same
problems in the bpf/benchs/*.

Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@....com.cn>
---
 .../selftests/bpf/benchs/bench_bloom_filter_map.c      | 10 +++++-----
 tools/testing/selftests/bpf/benchs/bench_bpf_loop.c    |  2 +-
 tools/testing/selftests/bpf/benchs/bench_rename.c      |  2 +-
 tools/testing/selftests/bpf/benchs/bench_ringbufs.c    |  6 +++---
 tools/testing/selftests/bpf/benchs/bench_strncmp.c     |  2 +-
 tools/testing/selftests/bpf/benchs/bench_trigger.c     |  2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
index 5bcb8a8cdeb2..fd1be1042516 100644
--- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
+++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
@@ -309,7 +309,7 @@ static void bloom_lookup_setup(void)
 	populate_maps();
 
 	link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
@@ -326,7 +326,7 @@ static void bloom_update_setup(void)
 	populate_maps();
 
 	link = bpf_program__attach(ctx.skel->progs.bloom_update);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
@@ -345,7 +345,7 @@ static void false_positive_setup(void)
 	populate_maps();
 
 	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
@@ -363,7 +363,7 @@ static void hashmap_with_bloom_setup(void)
 	populate_maps();
 
 	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
@@ -380,7 +380,7 @@ static void hashmap_no_bloom_setup(void)
 	populate_maps();
 
 	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
diff --git a/tools/testing/selftests/bpf/benchs/bench_bpf_loop.c b/tools/testing/selftests/bpf/benchs/bench_bpf_loop.c
index d0a6572bfab6..8dbdc28d26c8 100644
--- a/tools/testing/selftests/bpf/benchs/bench_bpf_loop.c
+++ b/tools/testing/selftests/bpf/benchs/bench_bpf_loop.c
@@ -85,7 +85,7 @@ static void setup(void)
 	}
 
 	link = bpf_program__attach(ctx.skel->progs.benchmark);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
diff --git a/tools/testing/selftests/bpf/benchs/bench_rename.c b/tools/testing/selftests/bpf/benchs/bench_rename.c
index 3c203b6d6a6e..66d63b92a28a 100644
--- a/tools/testing/selftests/bpf/benchs/bench_rename.c
+++ b/tools/testing/selftests/bpf/benchs/bench_rename.c
@@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog)
 	struct bpf_link *link;
 
 	link = bpf_program__attach(prog);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
diff --git a/tools/testing/selftests/bpf/benchs/bench_ringbufs.c b/tools/testing/selftests/bpf/benchs/bench_ringbufs.c
index c2554f9695ff..fff24ca82dc0 100644
--- a/tools/testing/selftests/bpf/benchs/bench_ringbufs.c
+++ b/tools/testing/selftests/bpf/benchs/bench_ringbufs.c
@@ -181,7 +181,7 @@ static void ringbuf_libbpf_setup(void)
 	}
 
 	link = bpf_program__attach(ctx->skel->progs.bench_ringbuf);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
@@ -271,7 +271,7 @@ static void ringbuf_custom_setup(void)
 	}
 
 	link = bpf_program__attach(ctx->skel->progs.bench_ringbuf);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program\n");
 		exit(1);
 	}
@@ -426,7 +426,7 @@ static void perfbuf_libbpf_setup(void)
 	}
 
 	link = bpf_program__attach(ctx->skel->progs.bench_perfbuf);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program\n");
 		exit(1);
 	}
diff --git a/tools/testing/selftests/bpf/benchs/bench_strncmp.c b/tools/testing/selftests/bpf/benchs/bench_strncmp.c
index 494b591c0289..dcb9ce5ffcb0 100644
--- a/tools/testing/selftests/bpf/benchs/bench_strncmp.c
+++ b/tools/testing/selftests/bpf/benchs/bench_strncmp.c
@@ -103,7 +103,7 @@ static void strncmp_attach_prog(struct bpf_program *prog)
 	struct bpf_link *link;
 
 	link = bpf_program__attach(prog);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
diff --git a/tools/testing/selftests/bpf/benchs/bench_trigger.c b/tools/testing/selftests/bpf/benchs/bench_trigger.c
index 0c481de2833d..bda930a8153c 100644
--- a/tools/testing/selftests/bpf/benchs/bench_trigger.c
+++ b/tools/testing/selftests/bpf/benchs/bench_trigger.c
@@ -61,7 +61,7 @@ static void attach_bpf(struct bpf_program *prog)
 	struct bpf_link *link;
 
 	link = bpf_program__attach(prog);
-	if (!link) {
+	if (IS_ERR(link)) {
 		fprintf(stderr, "failed to attach program!\n");
 		exit(1);
 	}
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ