Skip to content

Commit 5d4c6c1

Browse files
author
Benjamin Tissoires
committed
selftests/hid: fix compilation when bpf_wq and hid_device are not exported
This can happen in situations when CONFIG_HID_SUPPORT is set to no, or some complex situations where struct bpf_wq is not exported. So do the usual dance of hiding them before including vmlinux.h, and then redefining them and make use of CO-RE to have the correct offsets. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Fixes: fe8d561 ("selftests/hid: add wq test for hid_bpf_input_report()") Cc: [email protected] Acked-by: Jiri Kosina <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 0a3fe97 commit 5d4c6c1

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/testing/selftests/hid/progs/hid_bpf_helpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#define __HID_BPF_HELPERS_H
77

88
/* "undefine" structs and enums in vmlinux.h, because we "override" them below */
9+
#define bpf_wq bpf_wq___not_used
910
#define hid_bpf_ctx hid_bpf_ctx___not_used
1011
#define hid_bpf_ops hid_bpf_ops___not_used
12+
#define hid_device hid_device___not_used
1113
#define hid_report_type hid_report_type___not_used
1214
#define hid_class_request hid_class_request___not_used
1315
#define hid_bpf_attach_flags hid_bpf_attach_flags___not_used
@@ -27,8 +29,10 @@
2729

2830
#include "vmlinux.h"
2931

32+
#undef bpf_wq
3033
#undef hid_bpf_ctx
3134
#undef hid_bpf_ops
35+
#undef hid_device
3236
#undef hid_report_type
3337
#undef hid_class_request
3438
#undef hid_bpf_attach_flags
@@ -55,6 +59,14 @@ enum hid_report_type {
5559
HID_REPORT_TYPES,
5660
};
5761

62+
struct hid_device {
63+
unsigned int id;
64+
} __attribute__((preserve_access_index));
65+
66+
struct bpf_wq {
67+
__u64 __opaque[2];
68+
};
69+
5870
struct hid_bpf_ctx {
5971
struct hid_device *hid;
6072
__u32 allocated_size;

0 commit comments

Comments
 (0)