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

HID: export hid_report_type to uapi

When we are dealing with eBPF, we need to have access to the report type.
Currently our implementation differs from the USB standard, making it
impossible for users to know the exact value besides hardcoding it
themselves.

And instead of a blank define, convert it as an enum.

Note that we need to also do change in the ll_driver API, but given
that this will have a wider impact outside of this tree, we leave this
as a TODO for the future.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20220902132938.2409206-10-benjamin.tissoires@redhat.com

+27 -22
+7 -6
drivers/hid/hid-core.c
··· 55 55 */ 56 56 57 57 struct hid_report *hid_register_report(struct hid_device *device, 58 - unsigned int type, unsigned int id, 58 + enum hid_report_type type, unsigned int id, 59 59 unsigned int application) 60 60 { 61 61 struct hid_report_enum *report_enum = device->report_enum + type; ··· 967 967 * parsing. 968 968 */ 969 969 struct hid_report *hid_validate_values(struct hid_device *hid, 970 - unsigned int type, unsigned int id, 970 + enum hid_report_type type, unsigned int id, 971 971 unsigned int field_index, 972 972 unsigned int report_counts) 973 973 { ··· 1954 1954 } 1955 1955 EXPORT_SYMBOL_GPL(__hid_request); 1956 1956 1957 - int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, 1958 - int interrupt) 1957 + int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, 1958 + int interrupt) 1959 1959 { 1960 1960 struct hid_report_enum *report_enum = hid->report_enum + type; 1961 1961 struct hid_report *report; ··· 2019 2019 * 2020 2020 * This is data entry for lower layers. 2021 2021 */ 2022 - int hid_input_report(struct hid_device *hid, int type, u8 *data, u32 size, int interrupt) 2022 + int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, 2023 + int interrupt) 2023 2024 { 2024 2025 struct hid_report_enum *report_enum; 2025 2026 struct hid_driver *hdrv; ··· 2378 2377 */ 2379 2378 int hid_hw_raw_request(struct hid_device *hdev, 2380 2379 unsigned char reportnum, __u8 *buf, 2381 - size_t len, unsigned char rtype, int reqtype) 2380 + size_t len, enum hid_report_type rtype, int reqtype) 2382 2381 { 2383 2382 if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) 2384 2383 return -EINVAL;
+8 -16
include/linux/hid.h
··· 314 314 #define HID_BAT_ABSOLUTESTATEOFCHARGE 0x00850065 315 315 316 316 #define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076 317 - /* 318 - * HID report types --- Ouch! HID spec says 1 2 3! 319 - */ 320 - 321 - #define HID_INPUT_REPORT 0 322 - #define HID_OUTPUT_REPORT 1 323 - #define HID_FEATURE_REPORT 2 324 - 325 - #define HID_REPORT_TYPES 3 326 317 327 318 /* 328 319 * HID connect requests ··· 500 509 struct list_head hidinput_list; 501 510 struct list_head field_entry_list; /* ordered list of input fields */ 502 511 unsigned int id; /* id of this report */ 503 - unsigned int type; /* report type */ 512 + enum hid_report_type type; /* report type */ 504 513 unsigned int application; /* application usage for this report */ 505 514 struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */ 506 515 struct hid_field_entry *field_entries; /* allocated memory of input field_entry */ ··· 917 926 extern void hidinput_disconnect(struct hid_device *); 918 927 919 928 int hid_set_field(struct hid_field *, unsigned, __s32); 920 - int hid_input_report(struct hid_device *, int type, u8 *, u32, int); 929 + int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, 930 + int interrupt); 921 931 struct hid_field *hidinput_get_led_field(struct hid_device *hid); 922 932 unsigned int hidinput_count_leds(struct hid_device *hid); 923 933 __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); ··· 927 935 u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); 928 936 struct hid_device *hid_allocate_device(void); 929 937 struct hid_report *hid_register_report(struct hid_device *device, 930 - unsigned int type, unsigned int id, 938 + enum hid_report_type type, unsigned int id, 931 939 unsigned int application); 932 940 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size); 933 941 struct hid_report *hid_validate_values(struct hid_device *hid, 934 - unsigned int type, unsigned int id, 942 + enum hid_report_type type, unsigned int id, 935 943 unsigned int field_index, 936 944 unsigned int report_counts); 937 945 ··· 1103 1111 struct hid_report *report, int reqtype); 1104 1112 int hid_hw_raw_request(struct hid_device *hdev, 1105 1113 unsigned char reportnum, __u8 *buf, 1106 - size_t len, unsigned char rtype, int reqtype); 1114 + size_t len, enum hid_report_type rtype, int reqtype); 1107 1115 int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, size_t len); 1108 1116 1109 1117 /** ··· 1176 1184 return DIV_ROUND_UP(report->size, 8) + (report->id > 0); 1177 1185 } 1178 1186 1179 - int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, 1180 - int interrupt); 1187 + int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, 1188 + int interrupt); 1181 1189 1182 1190 /* HID quirks API */ 1183 1191 unsigned long hid_lookup_quirk(const struct hid_device *hdev);
+12
include/uapi/linux/hid.h
··· 43 43 #define USB_INTERFACE_PROTOCOL_MOUSE 2 44 44 45 45 /* 46 + * HID report types --- Ouch! HID spec says 1 2 3! 47 + */ 48 + 49 + enum hid_report_type { 50 + HID_INPUT_REPORT = 0, 51 + HID_OUTPUT_REPORT = 1, 52 + HID_FEATURE_REPORT = 2, 53 + 54 + HID_REPORT_TYPES, 55 + }; 56 + 57 + /* 46 58 * HID class requests 47 59 */ 48 60