diff mbox series

[bpf-next,3/3] selftests/bpf: Close obj in error paths in xdp_adjust_tail

Message ID 3e55e7dc99f0331566cc3bb140fc189a0f8943e9.1720521482.git.tanggeliang@kylinos.cn (mailing list archive)
State Accepted
Commit 52b49ec1b2c78deb258596c3b231201445ef5380
Headers show
Series BPF selftests misc fixes | expand

Commit Message

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

If bpf_object__load() fails in test_xdp_adjust_frags_tail_grow(), "obj"
opened before this should be closed. So use "goto out" to close it instead
of using "return" here.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alan Maguire July 10, 2024, 2:54 p.m. UTC | #1
On 09/07/2024 11:45, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> If bpf_object__load() fails in test_xdp_adjust_frags_tail_grow(), "obj"
> opened before this should be closed. So use "goto out" to close it instead
> of using "return" here.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

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

...with one suggestion below...

> ---
>  tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> index f09505f8b038..53d6ad8c2257 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> @@ -222,7 +222,7 @@ static void test_xdp_adjust_frags_tail_grow(void)
>  
>  	prog = bpf_object__next_program(obj, NULL);
>  	if (bpf_object__load(obj))
> -		return;
> +		goto out;
>

Nit: perhaps we should change this to

	if (!ASSERT_OK(bpf_object__load(obj), "obj_load"))
		goto out;

?
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index f09505f8b038..53d6ad8c2257 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -222,7 +222,7 @@  static void test_xdp_adjust_frags_tail_grow(void)
 
 	prog = bpf_object__next_program(obj, NULL);
 	if (bpf_object__load(obj))
-		return;
+		goto out;
 
 	prog_fd = bpf_program__fd(prog);