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

HID: bpf: allow write access to quirks field in struct hid_device

This allows to give more control from BPF during report descriptor fixup.
We already reset the quirks before calling ->probe(), so now we reset
it once before calling hid_bpf_rdesc_fixup().

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Link: https://patch.msgid.link/20241001-hid-bpf-hid-generic-v3-4-2ef1019468df@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

+10 -2
+1
drivers/hid/bpf/hid_bpf_struct_ops.c
··· 79 79 WRITE_RANGE(hid_device, name, true), 80 80 WRITE_RANGE(hid_device, uniq, true), 81 81 WRITE_RANGE(hid_device, phys, true), 82 + WRITE_RANGE(hid_device, quirks, false), 82 83 }; 83 84 #undef WRITE_RANGE 84 85 const struct btf_type *state = NULL;
+9 -2
drivers/hid/hid-core.c
··· 2709 2709 int ret; 2710 2710 2711 2711 if (!hdev->bpf_rsize) { 2712 + unsigned int quirks; 2713 + 2714 + /* reset the quirks that has been previously set */ 2715 + quirks = hid_lookup_quirk(hdev); 2716 + hdev->quirks = quirks; 2717 + 2712 2718 /* in case a bpf program gets detached, we need to free the old one */ 2713 2719 hid_free_bpf_rdesc(hdev); 2714 2720 ··· 2724 2718 /* call_hid_bpf_rdesc_fixup will always return a valid pointer */ 2725 2719 hdev->bpf_rdesc = call_hid_bpf_rdesc_fixup(hdev, hdev->dev_rdesc, 2726 2720 &hdev->bpf_rsize); 2721 + if (quirks ^ hdev->quirks) 2722 + hid_info(hdev, "HID-BPF toggled quirks on the device: %04x", 2723 + quirks ^ hdev->quirks); 2727 2724 } 2728 2725 2729 2726 if (!hid_check_device_match(hdev, hdrv, &id)) ··· 2736 2727 if (!hdev->devres_group_id) 2737 2728 return -ENOMEM; 2738 2729 2739 - /* reset the quirks that has been previously set */ 2740 - hdev->quirks = hid_lookup_quirk(hdev); 2741 2730 hdev->driver = hdrv; 2742 2731 2743 2732 if (hdrv->probe) {