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: 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 <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20231215100708.2265609-5-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Daniel Borkmann
00cdcd29 0d83786f

+11 -5
+11 -5
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
··· 222 222 "bpf_fentry_test2", 223 223 }; 224 224 __u64 cookies[2]; 225 + int saved_error; 225 226 226 227 addrs[0] = ksym_get_addr("bpf_fentry_test1"); 227 228 addrs[1] = ksym_get_addr("bpf_fentry_test2"); ··· 239 238 /* fail_1 - pattern and opts NULL */ 240 239 link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 241 240 NULL, NULL); 241 + saved_error = -errno; 242 242 if (!ASSERT_ERR_PTR(link, "fail_1")) 243 243 goto cleanup; 244 244 245 - if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_1_error")) 245 + if (!ASSERT_EQ(saved_error, -EINVAL, "fail_1_error")) 246 246 goto cleanup; 247 247 248 248 /* fail_2 - both addrs and syms set */ ··· 254 252 255 253 link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 256 254 NULL, &opts); 255 + saved_error = -errno; 257 256 if (!ASSERT_ERR_PTR(link, "fail_2")) 258 257 goto cleanup; 259 258 260 - if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_2_error")) 259 + if (!ASSERT_EQ(saved_error, -EINVAL, "fail_2_error")) 261 260 goto cleanup; 262 261 263 262 /* fail_3 - pattern and addrs set */ ··· 269 266 270 267 link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 271 268 "ksys_*", &opts); 269 + saved_error = -errno; 272 270 if (!ASSERT_ERR_PTR(link, "fail_3")) 273 271 goto cleanup; 274 272 275 - if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_3_error")) 273 + if (!ASSERT_EQ(saved_error, -EINVAL, "fail_3_error")) 276 274 goto cleanup; 277 275 278 276 /* fail_4 - pattern and cnt set */ ··· 284 280 285 281 link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 286 282 "ksys_*", &opts); 283 + saved_error = -errno; 287 284 if (!ASSERT_ERR_PTR(link, "fail_4")) 288 285 goto cleanup; 289 286 290 - if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_4_error")) 287 + if (!ASSERT_EQ(saved_error, -EINVAL, "fail_4_error")) 291 288 goto cleanup; 292 289 293 290 /* fail_5 - pattern and cookies */ ··· 299 294 300 295 link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 301 296 "ksys_*", &opts); 297 + saved_error = -errno; 302 298 if (!ASSERT_ERR_PTR(link, "fail_5")) 303 299 goto cleanup; 304 300 305 - if (!ASSERT_EQ(libbpf_get_error(link), -EINVAL, "fail_5_error")) 301 + if (!ASSERT_EQ(saved_error, -EINVAL, "fail_5_error")) 306 302 goto cleanup; 307 303 308 304 cleanup: