diff mbox series

[bpf-next,1/3] selftests/bpf: Null checks for links in bpf_tcp_ca

Message ID 3ac5d24825bdf666eae4089a8c69d8e97a6194d2.1720521482.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series BPF selftests misc fixes | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 17 of 17 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 82 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc

Commit Message

Geliang Tang July 9, 2024, 10:45 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch
platform, some "Segmentation fault" errors occur:

'''
 test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec
 test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
 #29/1    bpf_tcp_ca/dctcp:FAIL
 test_cubic:PASS:bpf_cubic__open_and_load 0 nsec
 test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
 #29/2    bpf_tcp_ca/cubic:FAIL
 test_dctcp_fallback:PASS:dctcp_skel 0 nsec
 test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec
 test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
 #29/4    bpf_tcp_ca/dctcp_fallback:FAIL
 test_write_sk_pacing:PASS:open_and_load 0 nsec
 test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
 #29/6    bpf_tcp_ca/write_sk_pacing:FAIL
 test_update_ca:PASS:open 0 nsec
 test_update_ca:FAIL:attach_struct_ops unexpected error: -524
 settcpca:FAIL:setsockopt unexpected setsockopt: \
					actual -1 == expected -1
 (network_helpers.c:99: errno: No such file or directory) \
					Failed to call post_socket_cb
 start_test:FAIL:start_server_str unexpected start_server_str: \
					actual -1 == expected -1
 test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
					actual 0 <= expected 0
 #29/9    bpf_tcp_ca/update_ca:FAIL
 #29      bpf_tcp_ca:FAIL
 Caught signal #11!
 Stack trace:
 ./test_progs(crash_handler+0x28)[0x5555567ed91c]
 linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0]
 ./test_progs(bpf_link__update_map+0x80)[0x555556824a78]
 ./test_progs(+0x94d68)[0x5555564c4d68]
 ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88]
 ./test_progs(+0x3bde54)[0x5555567ede54]
 ./test_progs(main+0x61c)[0x5555567efd54]
 /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208]
 /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c]
 ./test_progs(_start+0x48)[0x55555646bca8]
 Segmentation fault
'''

This is because BPF trampoline is not implemented on Loongarch yet,
"link" returned by bpf_map__attach_struct_ops() is NULL. test_progs
crashs when this NULL link passes to bpf_link__update_map(). This
patch adds NULL checks for all links in bpf_tcp_ca to fix these errors.
If "link" is NULL, goto the newly added label "out" to destroy the skel.

v2:
 - use "goto out" instead of "return" as Eduard suggested.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Alan Maguire July 10, 2024, 11:25 a.m. UTC | #1
On 09/07/2024 11:45, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch
> platform, some "Segmentation fault" errors occur:
> 
> '''
>  test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec
>  test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
>  #29/1    bpf_tcp_ca/dctcp:FAIL
>  test_cubic:PASS:bpf_cubic__open_and_load 0 nsec
>  test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
>  #29/2    bpf_tcp_ca/cubic:FAIL
>  test_dctcp_fallback:PASS:dctcp_skel 0 nsec
>  test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec
>  test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
>  #29/4    bpf_tcp_ca/dctcp_fallback:FAIL
>  test_write_sk_pacing:PASS:open_and_load 0 nsec
>  test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
>  #29/6    bpf_tcp_ca/write_sk_pacing:FAIL
>  test_update_ca:PASS:open 0 nsec
>  test_update_ca:FAIL:attach_struct_ops unexpected error: -524
>  settcpca:FAIL:setsockopt unexpected setsockopt: \
> 					actual -1 == expected -1
>  (network_helpers.c:99: errno: No such file or directory) \
> 					Failed to call post_socket_cb
>  start_test:FAIL:start_server_str unexpected start_server_str: \
> 					actual -1 == expected -1
>  test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
> 					actual 0 <= expected 0
>  #29/9    bpf_tcp_ca/update_ca:FAIL
>  #29      bpf_tcp_ca:FAIL
>  Caught signal #11!
>  Stack trace:
>  ./test_progs(crash_handler+0x28)[0x5555567ed91c]
>  linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0]
>  ./test_progs(bpf_link__update_map+0x80)[0x555556824a78]
>  ./test_progs(+0x94d68)[0x5555564c4d68]
>  ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88]
>  ./test_progs(+0x3bde54)[0x5555567ede54]
>  ./test_progs(main+0x61c)[0x5555567efd54]
>  /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208]
>  /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c]
>  ./test_progs(_start+0x48)[0x55555646bca8]
>  Segmentation fault
> '''
> 
> This is because BPF trampoline is not implemented on Loongarch yet,
> "link" returned by bpf_map__attach_struct_ops() is NULL. test_progs
> crashs when this NULL link passes to bpf_link__update_map(). This
> patch adds NULL checks for all links in bpf_tcp_ca to fix these errors.
> If "link" is NULL, goto the newly added label "out" to destroy the skel.
> 
> v2:
>  - use "goto out" instead of "return" as Eduard suggested.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

Maybe I'm missing it, but I'm not seeing this series on
patchwork.kernel.org/project/netdevbpf, so we don't have an associated
CI run (the series is in the kselftest patchwork however). Is there some
patchwork bot magic that will do this?

> ---
>  .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> index d842ff64bc2a..efc1bf2ff7de 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> @@ -411,7 +411,8 @@ static void test_update_ca(void)
>  		return;
>  
>  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> -	ASSERT_OK_PTR(link, "attach_struct_ops");
> +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> +		goto out;
>
>  	do_test(&opts);
>  	saved_ca1_cnt = skel->bss->ca1_cnt;
> @@ -425,6 +426,7 @@ static void test_update_ca(void)
>  	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
>  
>  	bpf_link__destroy(link);
> +out:
>  	tcp_ca_update__destroy(skel);
>  }
>  
> @@ -447,7 +449,8 @@ static void test_update_wrong(void)
>  		return;
>  
>  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> -	ASSERT_OK_PTR(link, "attach_struct_ops");
> +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> +		goto out;
>  
>  	do_test(&opts);
>  	saved_ca1_cnt = skel->bss->ca1_cnt;
> @@ -460,11 +463,13 @@ static void test_update_wrong(void)
>  	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
>  
>  	bpf_link__destroy(link);
> +out:
>  	tcp_ca_update__destroy(skel);
>  }
>  
>  static void test_mixed_links(void)
>  {
> +	struct bpf_link *link = NULL, *link_nl = NULL;
>  	struct cb_opts cb_opts = {
>  		.cc = "tcp_ca_update",
>  	};
> @@ -473,7 +478,6 @@ static void test_mixed_links(void)
>  		.cb_opts	= &cb_opts,
>  	};
>  	struct tcp_ca_update *skel;
> -	struct bpf_link *link, *link_nl;
>  	int err;
>  
>  	skel = tcp_ca_update__open_and_load();
> @@ -481,10 +485,12 @@ static void test_mixed_links(void)
>  		return;
>  
>  	link_nl = bpf_map__attach_struct_ops(skel->maps.ca_no_link);
> -	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
> +	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
> +		goto out;
>  
>  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> -	ASSERT_OK_PTR(link, "attach_struct_ops");
> +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> +		goto out;
>  
>  	do_test(&opts);
>  	ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
> @@ -492,6 +498,7 @@ static void test_mixed_links(void)
>  	err = bpf_link__update_map(link, skel->maps.ca_no_link);
>  	ASSERT_ERR(err, "update_map");
>  
> +out:
>  	bpf_link__destroy(link);
>  	bpf_link__destroy(link_nl);
>  	tcp_ca_update__destroy(skel);
> @@ -536,7 +543,8 @@ static void test_link_replace(void)
>  	bpf_link__destroy(link);
>  
>  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
> -	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
> +	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
> +		goto out;
>  
>  	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
>  	 *
> @@ -559,6 +567,7 @@ static void test_link_replace(void)
>  
>  	bpf_link__destroy(link);
>  
> +out:
>  	tcp_ca_update__destroy(skel);
>  }
>
Geliang Tang July 10, 2024, 1:07 p.m. UTC | #2
On Wed, 2024-07-10 at 12:25 +0100, Alan Maguire wrote:
> On 09/07/2024 11:45, Geliang Tang wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> > 
> > Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a
> > Loongarch
> > platform, some "Segmentation fault" errors occur:
> > 
> > '''
> >  test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec
> >  test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
> >  #29/1    bpf_tcp_ca/dctcp:FAIL
> >  test_cubic:PASS:bpf_cubic__open_and_load 0 nsec
> >  test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
> >  #29/2    bpf_tcp_ca/cubic:FAIL
> >  test_dctcp_fallback:PASS:dctcp_skel 0 nsec
> >  test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec
> >  test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
> >  #29/4    bpf_tcp_ca/dctcp_fallback:FAIL
> >  test_write_sk_pacing:PASS:open_and_load 0 nsec
> >  test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
> >  #29/6    bpf_tcp_ca/write_sk_pacing:FAIL
> >  test_update_ca:PASS:open 0 nsec
> >  test_update_ca:FAIL:attach_struct_ops unexpected error: -524
> >  settcpca:FAIL:setsockopt unexpected setsockopt: \
> > 					actual -1 == expected -1
> >  (network_helpers.c:99: errno: No such file or directory) \
> > 					Failed to call
> > post_socket_cb
> >  start_test:FAIL:start_server_str unexpected start_server_str: \
> > 					actual -1 == expected -1
> >  test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
> > 					actual 0 <= expected 0
> >  #29/9    bpf_tcp_ca/update_ca:FAIL
> >  #29      bpf_tcp_ca:FAIL
> >  Caught signal #11!
> >  Stack trace:
> >  ./test_progs(crash_handler+0x28)[0x5555567ed91c]
> >  linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0]
> >  ./test_progs(bpf_link__update_map+0x80)[0x555556824a78]
> >  ./test_progs(+0x94d68)[0x5555564c4d68]
> >  ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88]
> >  ./test_progs(+0x3bde54)[0x5555567ede54]
> >  ./test_progs(main+0x61c)[0x5555567efd54]
> >  /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208]
> >  /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c]
> >  ./test_progs(_start+0x48)[0x55555646bca8]
> >  Segmentation fault
> > '''
> > 
> > This is because BPF trampoline is not implemented on Loongarch yet,
> > "link" returned by bpf_map__attach_struct_ops() is NULL. test_progs
> > crashs when this NULL link passes to bpf_link__update_map(). This
> > patch adds NULL checks for all links in bpf_tcp_ca to fix these
> > errors.
> > If "link" is NULL, goto the newly added label "out" to destroy the
> > skel.
> > 
> > v2:
> >  - use "goto out" instead of "return" as Eduard suggested.
> > 
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> 
> Maybe I'm missing it, but I'm not seeing this series on
> patchwork.kernel.org/project/netdevbpf, so we don't have an
> associated
> CI run (the series is in the kselftest patchwork however). Is there
> some
> patchwork bot magic that will do this?

Thanks for your review. I want to do a small update for this patch, so
I changed this set as "Changes Requested". So they are not showed in
patchwork. v2 will be sent soon. I will add your "reviewed-by" tag in
it.

Thanks,
-Geliang

> 
> > ---
> >  .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++--
> > ----
> >  1 file changed, 15 insertions(+), 6 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> > b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> > index d842ff64bc2a..efc1bf2ff7de 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> > @@ -411,7 +411,8 @@ static void test_update_ca(void)
> >  		return;
> >  
> >  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> > -	ASSERT_OK_PTR(link, "attach_struct_ops");
> > +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> > +		goto out;
> > 
> >  	do_test(&opts);
> >  	saved_ca1_cnt = skel->bss->ca1_cnt;
> > @@ -425,6 +426,7 @@ static void test_update_ca(void)
> >  	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
> >  
> >  	bpf_link__destroy(link);
> > +out:
> >  	tcp_ca_update__destroy(skel);
> >  }
> >  
> > @@ -447,7 +449,8 @@ static void test_update_wrong(void)
> >  		return;
> >  
> >  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> > -	ASSERT_OK_PTR(link, "attach_struct_ops");
> > +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> > +		goto out;
> >  
> >  	do_test(&opts);
> >  	saved_ca1_cnt = skel->bss->ca1_cnt;
> > @@ -460,11 +463,13 @@ static void test_update_wrong(void)
> >  	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt,
> > "ca2_ca1_cnt");
> >  
> >  	bpf_link__destroy(link);
> > +out:
> >  	tcp_ca_update__destroy(skel);
> >  }
> >  
> >  static void test_mixed_links(void)
> >  {
> > +	struct bpf_link *link = NULL, *link_nl = NULL;
> >  	struct cb_opts cb_opts = {
> >  		.cc = "tcp_ca_update",
> >  	};
> > @@ -473,7 +478,6 @@ static void test_mixed_links(void)
> >  		.cb_opts	= &cb_opts,
> >  	};
> >  	struct tcp_ca_update *skel;
> > -	struct bpf_link *link, *link_nl;
> >  	int err;
> >  
> >  	skel = tcp_ca_update__open_and_load();
> > @@ -481,10 +485,12 @@ static void test_mixed_links(void)
> >  		return;
> >  
> >  	link_nl = bpf_map__attach_struct_ops(skel-
> > >maps.ca_no_link);
> > -	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
> > +	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
> > +		goto out;
> >  
> >  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
> > -	ASSERT_OK_PTR(link, "attach_struct_ops");
> > +	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
> > +		goto out;
> >  
> >  	do_test(&opts);
> >  	ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
> > @@ -492,6 +498,7 @@ static void test_mixed_links(void)
> >  	err = bpf_link__update_map(link, skel->maps.ca_no_link);
> >  	ASSERT_ERR(err, "update_map");
> >  
> > +out:
> >  	bpf_link__destroy(link);
> >  	bpf_link__destroy(link_nl);
> >  	tcp_ca_update__destroy(skel);
> > @@ -536,7 +543,8 @@ static void test_link_replace(void)
> >  	bpf_link__destroy(link);
> >  
> >  	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
> > -	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
> > +	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
> > +		goto out;
> >  
> >  	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
> >  	 *
> > @@ -559,6 +567,7 @@ static void test_link_replace(void)
> >  
> >  	bpf_link__destroy(link);
> >  
> > +out:
> >  	tcp_ca_update__destroy(skel);
> >  }
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index d842ff64bc2a..efc1bf2ff7de 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -411,7 +411,8 @@  static void test_update_ca(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -425,6 +426,7 @@  static void test_update_ca(void)
 	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -447,7 +449,8 @@  static void test_update_wrong(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -460,11 +463,13 @@  static void test_update_wrong(void)
 	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
 static void test_mixed_links(void)
 {
+	struct bpf_link *link = NULL, *link_nl = NULL;
 	struct cb_opts cb_opts = {
 		.cc = "tcp_ca_update",
 	};
@@ -473,7 +478,6 @@  static void test_mixed_links(void)
 		.cb_opts	= &cb_opts,
 	};
 	struct tcp_ca_update *skel;
-	struct bpf_link *link, *link_nl;
 	int err;
 
 	skel = tcp_ca_update__open_and_load();
@@ -481,10 +485,12 @@  static void test_mixed_links(void)
 		return;
 
 	link_nl = bpf_map__attach_struct_ops(skel->maps.ca_no_link);
-	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
+	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
+		goto out;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
@@ -492,6 +498,7 @@  static void test_mixed_links(void)
 	err = bpf_link__update_map(link, skel->maps.ca_no_link);
 	ASSERT_ERR(err, "update_map");
 
+out:
 	bpf_link__destroy(link);
 	bpf_link__destroy(link_nl);
 	tcp_ca_update__destroy(skel);
@@ -536,7 +543,8 @@  static void test_link_replace(void)
 	bpf_link__destroy(link);
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
-	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
+		goto out;
 
 	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
 	 *
@@ -559,6 +567,7 @@  static void test_link_replace(void)
 
 	bpf_link__destroy(link);
 
+out:
 	tcp_ca_update__destroy(skel);
 }