Skip to content

Commit 00cdcd2

Browse files
Hou Taoborkmann
authored andcommitted
selftests/bpf: Don't use libbpf_get_error() in kprobe_multi_test
Since libbpf v1.0, libbpf doesn't return error code embedded into the pointer iteself, libbpf_get_error() is deprecated and it is basically the same as using -errno directly. So replace the invocations of libbpf_get_error() by -errno in kprobe_multi_test. For libbpf_get_error() in test_attach_api_fails(), saving -errno before invoking ASSERT_xx() macros just in case that errno is overwritten by these macros. However, the invocation of libbpf_get_error() in get_syms() should be kept intact, because hashmap__new() still returns a pointer with embedded error code. Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0d83786 commit 00cdcd2

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static void test_attach_api_fails(void)
222222
"bpf_fentry_test2",
223223
};
224224
__u64 cookies[2];
225+
int saved_error;
225226

226227
addrs[0] = ksym_get_addr("bpf_fentry_test1");
227228
addrs[1] = ksym_get_addr("bpf_fentry_test2");
@@ -238,10 +239,11 @@ static void test_attach_api_fails(void)
238239
/* fail_1 - pattern and opts NULL */
239240
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual,
240241
NULL, NULL);
242+
saved_error = -errno;
241243
if (!ASSERT_ERR_PTR(link, "fail_1"))
242244
goto cleanup;
243245

244-
if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_1_error"))
246+
if (!ASSERT_EQ(saved_error, -EINVAL, "fail_1_error"))
245247
goto cleanup;
246248

247249
/* fail_2 - both addrs and syms set */
@@ -252,10 +254,11 @@ static void test_attach_api_fails(void)
252254

253255
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual,
254256
NULL, &opts);
257+
saved_error = -errno;
255258
if (!ASSERT_ERR_PTR(link, "fail_2"))
256259
goto cleanup;
257260

258-
if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_2_error"))
261+
if (!ASSERT_EQ(saved_error, -EINVAL, "fail_2_error"))
259262
goto cleanup;
260263

261264
/* fail_3 - pattern and addrs set */
@@ -266,10 +269,11 @@ static void test_attach_api_fails(void)
266269

267270
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual,
268271
"ksys_*", &opts);
272+
saved_error = -errno;
269273
if (!ASSERT_ERR_PTR(link, "fail_3"))
270274
goto cleanup;
271275

272-
if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_3_error"))
276+
if (!ASSERT_EQ(saved_error, -EINVAL, "fail_3_error"))
273277
goto cleanup;
274278

275279
/* fail_4 - pattern and cnt set */
@@ -280,10 +284,11 @@ static void test_attach_api_fails(void)
280284

281285
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual,
282286
"ksys_*", &opts);
287+
saved_error = -errno;
283288
if (!ASSERT_ERR_PTR(link, "fail_4"))
284289
goto cleanup;
285290

286-
if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_4_error"))
291+
if (!ASSERT_EQ(saved_error, -EINVAL, "fail_4_error"))
287292
goto cleanup;
288293

289294
/* fail_5 - pattern and cookies */
@@ -294,10 +299,11 @@ static void test_attach_api_fails(void)
294299

295300
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual,
296301
"ksys_*", &opts);
302+
saved_error = -errno;
297303
if (!ASSERT_ERR_PTR(link, "fail_5"))
298304
goto cleanup;
299305

300-
if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_5_error"))
306+
if (!ASSERT_EQ(saved_error, -EINVAL, "fail_5_error"))
301307
goto cleanup;
302308

303309
cleanup:

0 commit comments

Comments
 (0)