From 169480a352463eee65e825b1a934d7bebeb7967a Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 19 May 2026 17:22:50 +0300
Subject: [PATCH] hidapi/netbsd: import mainstream commit 7e994d8671:
https://github.com/libusb/hidapi/commit/7e994d8671 - authored by
Izumi Tsutsui:
netbsd: check not only addr 0 but also addr 1 to find root hubs
On NetBSD xhci(4) uses 'addr 0' for the root hub but all drivers for
other host controllers use 'addr 1' for the root hub.
https://gnats.netbsd.org/60073
---
src/hidapi/netbsd/hid.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/hidapi/netbsd/hid.c b/src/hidapi/netbsd/hid.c
index d88630db871d7..5f5858504d727 100644
--- a/src/hidapi/netbsd/hid.c
+++ b/src/hidapi/netbsd/hid.c
@@ -711,6 +711,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
for (size_t i = 0; i < len; i++) {
char devpath[USB_MAX_DEVNAMELEN];
int bus;
+ struct hid_device_info *prev_end;
strlcpy(devpath, "/dev/", sizeof(devpath));
strlcat(devpath, arr[i], sizeof(devpath));
@@ -719,7 +720,17 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
if (bus == -1)
continue;
+ /*
+ * ehci/ohci/uhci/dwctwo etc. use 'addr 1' for root hubs
+ * but xhci uses 'addr 0' on NetBSD.
+ * Check addr 0 (that would be unused on other than xhci)
+ * and then check addr 1 if there is no device at addr 0.
+ */
+ prev_end = hed.end;
enumerate_usb_devices(bus, 0, hid_enumerate_callback, &hed);
+ if (hed.end == prev_end)
+ enumerate_usb_devices(bus, 1,
+ hid_enumerate_callback, &hed);
close(bus);
}