[PATCH 3/9] HID: core: Reject mixing numbered and unnumbered reports

From: Dmitry Torokhov

Date: Mon Oct 12 2026 - 23:42:45 EST


According to the Device Class Definition for HID, if any report of a
given type includes a Report ID tag, all reports of that type must
include a Report ID tag. Mixing numbered and unnumbered reports within
the same report enumeration is invalid and causes confusion when sizing
and parsing incoming and outgoing transfers.

Reject descriptors that attempt to mix numbered and unnumbered reports
within the same report enumeration by warning and aborting report
registration.

Assisted-by: LLM
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-core.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index a33e864a25f9..3a9bd56dbf85 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -96,6 +96,12 @@ struct hid_report *hid_register_report(struct hid_device *device,
if (report_enum->report_id_hash[id])
return report_enum->report_id_hash[id];

+ if ((id == 0 && report_enum->numbered) ||
+ (id != 0 && report_enum->report_id_hash[0])) {
+ hid_warn(device, "not allowed to mix numbered and unnumbered reports\n");
+ return NULL;
+ }
+
report = kzalloc_obj(struct hid_report);
if (!report)
return NULL;

--
2.56.0.385.gd3acb90ef8-goog