From: Geliang Tang Date: Thu, 23 May 2024 06:49:57 +0000 (+0800) Subject: selftests/bpf: Fix tx_prog_fd values in test_sockmap X-Git-Tag: v6.11-rc1~163^2~222^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d95ba15b97847f4ae520db83bd98b61d50fb3068;p=thirdparty%2Fkernel%2Flinux.git selftests/bpf: Fix tx_prog_fd values in test_sockmap The values of tx_prog_fd in run_options() should not be 0, so set it as -1 in else branch, and test it using "if (tx_prog_fd > 0)" condition, not "if (tx_prog_fd)" or "if (tx_prog_fd >= 0)". Signed-off-by: Geliang Tang Signed-off-by: Daniel Borkmann Tested-by: Jakub Sitnicki Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/08b20ffc544324d40939efeae93800772a91a58e.1716446893.git.tanggeliang@kylinos.cn --- diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index ddc6a9cef36f9..892a690c4e7b4 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -1027,9 +1027,9 @@ run: else if (txmsg_drop) tx_prog_fd = prog_fd[8]; else - tx_prog_fd = 0; + tx_prog_fd = -1; - if (tx_prog_fd) { + if (tx_prog_fd > 0) { int redir_fd, i = 0; err = bpf_prog_attach(tx_prog_fd, @@ -1285,7 +1285,7 @@ out: bpf_prog_detach2(prog_fd[0], map_fd[8], BPF_SK_SKB_STREAM_PARSER); bpf_prog_detach2(prog_fd[2], map_fd[8], BPF_SK_SKB_STREAM_VERDICT); - if (tx_prog_fd >= 0) + if (tx_prog_fd > 0) bpf_prog_detach2(tx_prog_fd, map_fd[1], BPF_SK_MSG_VERDICT); for (i = 0; i < 8; i++) {