From: anton Date: Sun, 29 Aug 2021 18:21:16 +0000 (+0000) Subject: Make the ucc match criteria more stringent by requiring at least one X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9a1fff4fbbef2056ad25f69dc4dc54ee3b04940f;p=openbsd Make the ucc match criteria more stringent by requiring at least one usage greater than zero. Usage zero is defined as unassigned by the specification and cannot be mapped to anything sensible. Prevents ucc from attaching to bunch of odd report IDs from a Lenovo ThinkPad USB-C Dock which only exposes the unassigned usage. This is not a problem in practice but I think we're better attaching them as uhid devices instead as ucc cannot provide any functionality. Thanks to Mario Peter for reporting and testing. --- diff --git a/sys/dev/usb/ucc.c b/sys/dev/usb/ucc.c index d7aba7b5f82..d2b169d03ec 100644 --- a/sys/dev/usb/ucc.c +++ b/sys/dev/usb/ucc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ucc.c,v 1.16 2021/08/29 18:20:18 anton Exp $ */ +/* $OpenBSD: ucc.c,v 1.17 2021/08/29 18:21:16 anton Exp $ */ /* * Copyright (c) 2021 Anton Lindqvist @@ -839,19 +839,21 @@ ucc_hid_match(void *desc, int descsiz, uint8_t repid) { struct hid_item hi; struct hid_data *hd; - int match = 0; + int32_t maxusage = 0; hd = hid_start_parse(desc, descsiz, hid_input); while (hid_get_item(hd, &hi)) { if (hi.report_ID == repid && hi.kind == hid_input && HID_GET_USAGE_PAGE(hi.usage) == HUP_CONSUMER) { - match = 1; - break; + if (HID_GET_USAGE(hi.usage_maximum) > maxusage) + maxusage = HID_GET_USAGE(hi.usage_maximum); + else if (HID_GET_USAGE(hi.usage) > maxusage) + maxusage = HID_GET_USAGE(hi.usage); } } hid_end_parse(hd); - return match; + return maxusage > 0; } /*