All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: <cgel.zte@gmail.com>, <shuah@kernel.org>, <ast@kernel.org>,
	<daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kafai@fb.com>, <songliubraving@fb.com>,
	<yhs@fb.com>, <john.fastabend@gmail.com>, <kpsingh@kernel.org>,
	<joannekoong@fb.com>, <lv.ruyi@zte.com.cn>, <toke@redhat.com>,
	<linux-kselftest@vger.kernel.org>, <netdev@vger.kernel.org>,
	<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] bpf/benchs: fix error check return value of bpf_program__attach()
Date: Wed, 13 Apr 2022 22:33:12 +0800	[thread overview]
Message-ID: <3dab1e4b-2317-4730-f699-627583ff759d@huawei.com> (raw)
In-Reply-To: <20220413093123.2538001-1-lv.ruyi@zte.com.cn>

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


      reply	other threads:[~2022-04-13 14:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13  9:31 [PATCH] bpf/benchs: fix error check return value of bpf_program__attach() cgel.zte
2022-04-13 14:33 ` Hou Tao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3dab1e4b-2317-4730-f699-627583ff759d@huawei.com \
    --to=houtao1@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgel.zte@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=joannekoong@fb.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lv.ruyi@zte.com.cn \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.com \
    --cc=zealci@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.