diff mbox series

bpf/benchs: fix error check return value of bpf_program__attach()

Message ID 20220413093123.2538001-1-lv.ruyi@zte.com.cn
State New
Headers show
Series bpf/benchs: fix error check return value of bpf_program__attach() | expand

Commit Message

Lv Ruyi April 13, 2022, 9:31 a.m. UTC
From: Lv Ruyi <lv.ruyi@zte.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@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.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(-)

Comments

Hou Tao April 13, 2022, 2:33 p.m. UTC | #1
Hi,

On 4/13/2022 5:31 PM, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.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/*.
The fix is unnecessary. Because libbpf has been setup asĀ  LIBBPF_STRICT_ALL mode
in setup_libbpf() of bench.c, so when bpf_program__attach() fails, it will
return NULL instead of ERR_PTR(err).

>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.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);
>  	}
diff mbox series

Patch

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);
 	}