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

selftests/bpf: do not pass NULL for non-nullable params in dummy_st_ops

dummy_st_ops.test_2 and dummy_st_ops.test_sleepable do not have their
'state' parameter marked as nullable. Update dummy_st_ops.c to avoid
passing NULL for such parameters, as the next patch would allow kernel
to enforce this restriction.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20240424012821.595216-4-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Eduard Zingerman and committed by
Alexei Starovoitov
f612210d 3b3b84aa

+6 -3
+5 -2
tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
··· 98 98 99 99 static void test_dummy_multiple_args(void) 100 100 { 101 - __u64 args[5] = {0, -100, 0x8a5f, 'c', 0x1234567887654321ULL}; 101 + struct bpf_dummy_ops_state st = { 7 }; 102 + __u64 args[5] = {(__u64)&st, -100, 0x8a5f, 'c', 0x1234567887654321ULL}; 102 103 LIBBPF_OPTS(bpf_test_run_opts, attr, 103 104 .ctx_in = args, 104 105 .ctx_size_in = sizeof(args), ··· 116 115 fd = bpf_program__fd(skel->progs.test_2); 117 116 err = bpf_prog_test_run_opts(fd, &attr); 118 117 ASSERT_OK(err, "test_run"); 118 + args[0] = 7; 119 119 for (i = 0; i < ARRAY_SIZE(args); i++) { 120 120 snprintf(name, sizeof(name), "arg %zu", i); 121 121 ASSERT_EQ(skel->bss->test_2_args[i], args[i], name); ··· 127 125 128 126 static void test_dummy_sleepable(void) 129 127 { 130 - __u64 args[1] = {0}; 128 + struct bpf_dummy_ops_state st; 129 + __u64 args[1] = {(__u64)&st}; 131 130 LIBBPF_OPTS(bpf_test_run_opts, attr, 132 131 .ctx_in = args, 133 132 .ctx_size_in = sizeof(args),
+1 -1
tools/testing/selftests/bpf/progs/dummy_st_ops_success.c
··· 34 34 int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2, 35 35 char a3, unsigned long a4) 36 36 { 37 - test_2_args[0] = (unsigned long)state; 37 + test_2_args[0] = state->val; 38 38 test_2_args[1] = a1; 39 39 test_2_args[2] = a2; 40 40 test_2_args[3] = a3;