Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Task_work selftest cleanup fixes

task_work selftest does not properly handle cleanup during failures:
* destroy bpf_link
* perf event fd is passed to bpf_link, no need to close it if link was
created successfully
* goto cleanup if fork() failed, close pipe.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250924142954.129519-2-mykyta.yatsenko5@gmail.com

authored by

Mykyta Yatsenko and committed by
Andrii Nakryiko
5730dacb dd948aa6

+11 -4
+11 -4
tools/testing/selftests/bpf/prog_tests/test_task_work.c
··· 55 55 struct task_work *skel; 56 56 struct bpf_program *prog; 57 57 struct bpf_map *map; 58 - struct bpf_link *link; 59 - int err, pe_fd = 0, pid, status, pipefd[2]; 58 + struct bpf_link *link = NULL; 59 + int err, pe_fd = -1, pid, status, pipefd[2]; 60 60 char user_string[] = "hello world"; 61 61 62 62 if (!ASSERT_NEQ(pipe(pipefd), -1, "pipe")) ··· 77 77 (void)num; 78 78 exit(0); 79 79 } 80 - ASSERT_GT(pid, 0, "fork() failed"); 80 + if (!ASSERT_GT(pid, 0, "fork() failed")) { 81 + close(pipefd[0]); 82 + close(pipefd[1]); 83 + return; 84 + } 81 85 82 86 skel = task_work__open(); 83 87 if (!ASSERT_OK_PTR(skel, "task_work__open")) ··· 116 112 if (!ASSERT_OK_PTR(link, "attach_perf_event")) 117 113 goto cleanup; 118 114 115 + /* perf event fd ownership is passed to bpf_link */ 116 + pe_fd = -1; 119 117 close(pipefd[0]); 120 118 write(pipefd[1], user_string, 1); 121 119 close(pipefd[1]); ··· 132 126 cleanup: 133 127 if (pe_fd >= 0) 134 128 close(pe_fd); 129 + bpf_link__destroy(link); 135 130 task_work__destroy(skel); 136 - if (pid) { 131 + if (pid > 0) { 137 132 close(pipefd[0]); 138 133 write(pipefd[1], user_string, 1); 139 134 close(pipefd[1]);