Skip to content

Commit

Permalink
usb/hid: Handle reports not providing enough usages for a usage page
Browse files Browse the repository at this point in the history
Do as Linux does, that is, duplicate the last usage if we're short.

Fixes managarm#462.
  • Loading branch information
qookei committed Jun 4, 2024
1 parent 497c44c commit 1bacadc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/usb/devices/hid/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1bacadc

Please sign in to comment.