the context is allocated the first time a program of type DEVICE_EVENT is attached to the device. To not add too much jumps in the code for the general device handling, call hid_bpf_raw_event() only if we know that a program has been attached once during the life of the device. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@xxxxxxxxxx> --- new in v2 --- drivers/hid/hid-core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index d0e015986e17..2b49f6064a40 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1751,10 +1751,13 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, u8 *cdata; int ret = 0; - data = hid_bpf_raw_event(hid, data, &size); - if (IS_ERR(data)) { - ret = PTR_ERR(data); - goto out; + /* we pre-test if ctx is available here to cut the calls at the earliest */ + if (hid->bpf.ctx) { + data = hid_bpf_raw_event(hid, data, &size); + if (IS_ERR(data)) { + ret = PTR_ERR(data); + goto out; + } } report = hid_get_report(report_enum, data); -- 2.35.1