From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: Yang Yingliang <yangyingliang@huawei.com>,
Joanne Koong <joannekoong@fb.com>,
Andrii Nakryiko <andrii@kernel.org>,
LKML <linux-kernel@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>, Shuah Khan <shuah@kernel.org>,
Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
Date: Mon, 1 Nov 2021 15:30:31 -0700 [thread overview]
Message-ID: <CAADnVQ+aeAnBEN=dp92q0RBXT+Um1ha4_F=sQ7fr08Sa3qauLQ@mail.gmail.com> (raw)
In-Reply-To: <90518c5d-36ea-ec97-9f14-0687fdd6074f@fb.com>
On Mon, Nov 1, 2021 at 3:21 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 11/1/21 3:00 PM, Alexei Starovoitov wrote:
> > On Mon, Nov 1, 2021 at 5:35 AM Yang Yingliang <yangyingliang@huawei.com> 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>
> >> Acked-by: Yonghong Song <yhs@fb.com>
> >> ---
> >> v2:
> >> don't use 'int err'
> >> ---
> >> .../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
> >> 1 file changed, 5 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..4afaa4adb327 100644
> >> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> >> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> >> @@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
> >> populate_maps();
> >>
> >> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> >> - if (!link) {
> >> + if (libbpf_get_error(link)) {
> >
> > Please use ASSERT_OK_PTR() instead.
> > See how other tests are doing it.
>
> I actually looked at this. ASSERT_OK_PTR() is defined in test_progs.h
> and test_progs.h is ONLY included in files which eventually linked to
> test_progs. That is why I didn't recommend to use ASSERT_OK_PTR().
>
> Maybe it is okay to include test_progs.h in benchs/*.c. Or we may
> want to refactor to a separate header file to contain these macros
> which can be used for test_progs.h and other applications.
hmm.
Looks like bench_ringbufs.c has the same issue doing:
if (!link)
and bench_rename.c too.
Probably would be good to fix in all bench-s.
If test_progs.h cannot be included directly
copy-pasting ASSERT_OK_PTR in a reduced form into bench.h
is probably cleaner than open coding libbpf_get_error.
next prev parent reply other threads:[~2021-11-01 22:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-01 12:43 [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach() Yang Yingliang
2021-11-01 22:00 ` Alexei Starovoitov
2021-11-01 22:21 ` Yonghong Song
2021-11-01 22:30 ` Alexei Starovoitov [this message]
2021-11-02 2:46 ` Andrii Nakryiko
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='CAADnVQ+aeAnBEN=dp92q0RBXT+Um1ha4_F=sQ7fr08Sa3qauLQ@mail.gmail.com' \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=joannekoong@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=yangyingliang@huawei.com \
--cc=yhs@fb.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;
as well as URLs for NNTP newsgroup(s).