From: Yonghong Song <yhs@fb.com>
To: Yang Yingliang <yangyingliang@huawei.com>,
<linux-kernel@vger.kernel.org>, <bpf@vger.kernel.org>
Cc: <linux-kselftest@vger.kernel.org>, <shuah@kernel.org>, <ast@kernel.org>
Subject: Re: [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach()
Date: Sun, 31 Oct 2021 21:13:47 -0700 [thread overview]
Message-ID: <3d7c321e-6099-a7f4-bffe-06d4bf48536d@fb.com> (raw)
In-Reply-To: <20211030093051.2609665-1-yangyingliang@huawei.com>
On 10/30/21 2:30 AM, Yang Yingliang wrote:
> If bpf_program__attach() fails, it never returns NULL,
> we should use libbpf_get_error() to check the return value.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Thanks for the fix. LGTM with a nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> .../bpf/benchs/bench_bloom_filter_map.c | 20 ++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 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 6eeeed2913e6..6879340b20c4 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> @@ -296,6 +296,7 @@ static struct bloom_filter_bench *setup_skeleton(void)
> static void bloom_lookup_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_array_map = true;
>
> @@ -304,7 +305,8 @@ static void bloom_lookup_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
There is no need to define 'int err', you can just do
if (libbpf_get_error(link))
The same for a few 'int err' below.
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -313,6 +315,7 @@ static void bloom_lookup_setup(void)
> static void bloom_update_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_array_map = true;
>
> @@ -321,7 +324,8 @@ static void bloom_update_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_update);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -330,6 +334,7 @@ static void bloom_update_setup(void)
> static void false_positive_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
> ctx.hashmap_use_bloom = true;
> @@ -340,7 +345,8 @@ static void false_positive_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -349,6 +355,7 @@ static void false_positive_setup(void)
> static void hashmap_with_bloom_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
> ctx.hashmap_use_bloom = true;
> @@ -358,7 +365,8 @@ static void hashmap_with_bloom_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -367,6 +375,7 @@ static void hashmap_with_bloom_setup(void)
> static void hashmap_no_bloom_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
>
> @@ -375,7 +384,8 @@ static void hashmap_no_bloom_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
>
prev parent reply other threads:[~2021-11-01 4:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-30 9:30 Yang Yingliang
2021-11-01 4:13 ` Yonghong Song [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=3d7c321e-6099-a7f4-bffe-06d4bf48536d@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=yangyingliang@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®