Skip to content

Commit facdbdf

Browse files
author
Benjamin Tissoires
committed
selftests/hid: add test for attaching multiple time the same struct_ops
Turns out that we would en up in a bad state if we attempt to attach twice the same HID-BPF struct_ops, so have a test for it. Link: https://patch.msgid.link/20240723-fix-6-11-bpf-v1-4-b9d770346784@kernel.org Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent acd34cf commit facdbdf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tools/testing/selftests/hid/hid_bpf.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,24 @@ TEST_F(hid_bpf, subprog_raw_event)
694694
ASSERT_EQ(buf[2], 52);
695695
}
696696

697+
/*
698+
* Attach hid_first_event to the given uhid device,
699+
* attempt at re-attaching it, we should not lock and
700+
* return an invalid struct bpf_link
701+
*/
702+
TEST_F(hid_bpf, multiple_attach)
703+
{
704+
const struct test_program progs[] = {
705+
{ .name = "hid_first_event" },
706+
};
707+
struct bpf_link *link;
708+
709+
LOAD_PROGRAMS(progs);
710+
711+
link = bpf_map__attach_struct_ops(self->skel->maps.first_event);
712+
ASSERT_NULL(link) TH_LOG("unexpected return value when re-attaching the struct_ops");
713+
}
714+
697715
/*
698716
* Ensures that we can attach/detach programs
699717
*/

0 commit comments

Comments
 (0)