Skip to content

Commit 1703612

Browse files
olsajirianakryiko
authored andcommitted
selftests/bpf: Use bpf_link__destroy in fill_link_info tests
The fill_link_info test keeps skeleton open and just creates various links. We are wrongly calling bpf_link__detach after each test to close them, we need to call bpf_link__destroy. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Acked-by: Yafang Shao <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e56fdbf commit 1703612

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

tools/testing/selftests/bpf/prog_tests/fill_link_info.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
140140
.retprobe = type == BPF_PERF_EVENT_KRETPROBE,
141141
);
142142
ssize_t entry_offset = 0;
143+
struct bpf_link *link;
143144
int link_fd, err;
144145

145-
skel->links.kprobe_run = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run,
146-
KPROBE_FUNC, &opts);
147-
if (!ASSERT_OK_PTR(skel->links.kprobe_run, "attach_kprobe"))
146+
link = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run, KPROBE_FUNC, &opts);
147+
if (!ASSERT_OK_PTR(link, "attach_kprobe"))
148148
return;
149149

150-
link_fd = bpf_link__fd(skel->links.kprobe_run);
150+
link_fd = bpf_link__fd(link);
151151
if (!invalid) {
152152
/* See also arch_adjust_kprobe_addr(). */
153153
if (skel->kconfig->CONFIG_X86_KERNEL_IBT)
@@ -157,39 +157,41 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
157157
} else {
158158
kprobe_fill_invalid_user_buffer(link_fd);
159159
}
160-
bpf_link__detach(skel->links.kprobe_run);
160+
bpf_link__destroy(link);
161161
}
162162

163163
static void test_tp_fill_link_info(struct test_fill_link_info *skel)
164164
{
165+
struct bpf_link *link;
165166
int link_fd, err;
166167

167-
skel->links.tp_run = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
168-
if (!ASSERT_OK_PTR(skel->links.tp_run, "attach_tp"))
168+
link = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
169+
if (!ASSERT_OK_PTR(link, "attach_tp"))
169170
return;
170171

171-
link_fd = bpf_link__fd(skel->links.tp_run);
172+
link_fd = bpf_link__fd(link);
172173
err = verify_perf_link_info(link_fd, BPF_PERF_EVENT_TRACEPOINT, 0, 0, 0);
173174
ASSERT_OK(err, "verify_perf_link_info");
174-
bpf_link__detach(skel->links.tp_run);
175+
bpf_link__destroy(link);
175176
}
176177

177178
static void test_uprobe_fill_link_info(struct test_fill_link_info *skel,
178179
enum bpf_perf_event_type type)
179180
{
181+
struct bpf_link *link;
180182
int link_fd, err;
181183

182-
skel->links.uprobe_run = bpf_program__attach_uprobe(skel->progs.uprobe_run,
183-
type == BPF_PERF_EVENT_URETPROBE,
184-
0, /* self pid */
185-
UPROBE_FILE, uprobe_offset);
186-
if (!ASSERT_OK_PTR(skel->links.uprobe_run, "attach_uprobe"))
184+
link = bpf_program__attach_uprobe(skel->progs.uprobe_run,
185+
type == BPF_PERF_EVENT_URETPROBE,
186+
0, /* self pid */
187+
UPROBE_FILE, uprobe_offset);
188+
if (!ASSERT_OK_PTR(link, "attach_uprobe"))
187189
return;
188190

189-
link_fd = bpf_link__fd(skel->links.uprobe_run);
191+
link_fd = bpf_link__fd(link);
190192
err = verify_perf_link_info(link_fd, type, 0, uprobe_offset, 0);
191193
ASSERT_OK(err, "verify_perf_link_info");
192-
bpf_link__detach(skel->links.uprobe_run);
194+
bpf_link__destroy(link);
193195
}
194196

195197
static int verify_kmulti_link_info(int fd, bool retprobe)
@@ -278,24 +280,24 @@ static void test_kprobe_multi_fill_link_info(struct test_fill_link_info *skel,
278280
bool retprobe, bool invalid)
279281
{
280282
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
283+
struct bpf_link *link;
281284
int link_fd, err;
282285

283286
opts.syms = kmulti_syms;
284287
opts.cnt = KMULTI_CNT;
285288
opts.retprobe = retprobe;
286-
skel->links.kmulti_run = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run,
287-
NULL, &opts);
288-
if (!ASSERT_OK_PTR(skel->links.kmulti_run, "attach_kprobe_multi"))
289+
link = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run, NULL, &opts);
290+
if (!ASSERT_OK_PTR(link, "attach_kprobe_multi"))
289291
return;
290292

291-
link_fd = bpf_link__fd(skel->links.kmulti_run);
293+
link_fd = bpf_link__fd(link);
292294
if (!invalid) {
293295
err = verify_kmulti_link_info(link_fd, retprobe);
294296
ASSERT_OK(err, "verify_kmulti_link_info");
295297
} else {
296298
verify_kmulti_invalid_user_buffer(link_fd);
297299
}
298-
bpf_link__detach(skel->links.kmulti_run);
300+
bpf_link__destroy(link);
299301
}
300302

301303
void test_fill_link_info(void)

0 commit comments

Comments
 (0)