lkml.org 
[lkml]   [2021]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
From


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.

>

\
 
 \ /
  Last update: 2021-11-01 23:23    [W:0.073 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site