From 1bacadca4807cfa69e1aed5dc36d255a77aa6417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?= Date: Mon, 3 Jun 2024 07:42:41 +0200 Subject: [PATCH] usb/hid: Handle reports not providing enough usages for a usage page Do as Linux does, that is, duplicate the last usage if we're short. Fixes #462. --- drivers/usb/devices/hid/src/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/devices/hid/src/main.cpp b/drivers/usb/devices/hid/src/main.cpp index 7621182c4..6666822be 100644 --- a/drivers/usb/devices/hid/src/main.cpp +++ b/drivers/usb/devices/hid/src/main.cpp @@ -307,8 +307,12 @@ void HidDevice::parseReportDescriptor(proto::Device, uint8_t *p, uint8_t* limit) if(local.usage.empty()) { actual_id = local.usageMin.value() + i; }else{ - assert(local.usage.size() == global.reportCount.value()); - actual_id = local.usage[i]; + // Duplicate the last usage if we have excess value, as Linux does. + if (i >= local.usage.size()) { + actual_id = local.usage.back(); + } else { + actual_id = local.usage[i]; + } } if(!global.logicalMin || !global.logicalMax)