Skip to content

Commit

Permalink
selftests/bpf: do not pass NULL for non-nullable params in dummy_st_ops
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eduard Zingerman authored and Alexei Starovoitov committed Apr 25, 2024
1 parent 3b3b84a commit f612210
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ static void test_dummy_init_ptr_arg(void)

static void test_dummy_multiple_args(void)
{
__u64 args[5] = {0, -100, 0x8a5f, 'c', 0x1234567887654321ULL};
struct bpf_dummy_ops_state st = { 7 };
__u64 args[5] = {(__u64)&st, -100, 0x8a5f, 'c', 0x1234567887654321ULL};
LIBBPF_OPTS(bpf_test_run_opts, attr,
.ctx_in = args,
.ctx_size_in = sizeof(args),
Expand All @@ -115,6 +116,7 @@ static void test_dummy_multiple_args(void)
fd = bpf_program__fd(skel->progs.test_2);
err = bpf_prog_test_run_opts(fd, &attr);
ASSERT_OK(err, "test_run");
args[0] = 7;
for (i = 0; i < ARRAY_SIZE(args); i++) {
snprintf(name, sizeof(name), "arg %zu", i);
ASSERT_EQ(skel->bss->test_2_args[i], args[i], name);
Expand All @@ -125,7 +127,8 @@ static void test_dummy_multiple_args(void)

static void test_dummy_sleepable(void)
{
__u64 args[1] = {0};
struct bpf_dummy_ops_state st;
__u64 args[1] = {(__u64)&st};
LIBBPF_OPTS(bpf_test_run_opts, attr,
.ctx_in = args,
.ctx_size_in = sizeof(args),
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/progs/dummy_st_ops_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SEC("struct_ops/test_2")
int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
char a3, unsigned long a4)
{
test_2_args[0] = (unsigned long)state;
test_2_args[0] = state->val;
test_2_args[1] = a1;
test_2_args[2] = a2;
test_2_args[3] = a3;
Expand Down

0 comments on commit f612210

Please sign in to comment.