Don't enumerate devices we can't open
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index bcf51ea..90ca815 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -608,25 +608,25 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Check the VID/PID against the arguments */
if ((vendor_id == 0x0 || vendor_id == dev_vid) &&
(product_id == 0x0 || product_id == dev_pid)) {
- struct hid_device_info *tmp;
+ res = libusb_open(dev, &handle);
- /* VID/PID match. Create the record. */
- tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
- if (cur_dev) {
- cur_dev->next = tmp;
- }
- else {
- root = tmp;
- }
- cur_dev = tmp;
+ if (res >= 0) {
+ struct hid_device_info *tmp;
- /* Fill out the record */
- cur_dev->next = NULL;
- cur_dev->path = make_path(dev, interface_num);
+ /* VID/PID match. Create the record. */
+ tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
+ if (cur_dev) {
+ cur_dev->next = tmp;
+ }
+ else {
+ root = tmp;
+ }
+ cur_dev = tmp;
- res = libusb_open(dev, &handle);
+ /* Fill out the record */
+ cur_dev->next = NULL;
+ cur_dev->path = make_path(dev, interface_num);
- if (res >= 0) {
/* Serial Number */
if (desc.iSerialNumber > 0)
cur_dev->serial_number =
@@ -704,19 +704,22 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
#endif /* INVASIVE_GET_USAGE */
libusb_close(handle);
- }
- /* VID/PID */
- cur_dev->vendor_id = dev_vid;
- cur_dev->product_id = dev_pid;
-
- /* Release Number */
- cur_dev->release_number = desc.bcdDevice;
-
- /* Interface Number */
- cur_dev->interface_number = interface_num;
- cur_dev->interface_class = intf_desc->bInterfaceClass;
- cur_dev->interface_subclass = intf_desc->bInterfaceSubClass;
- cur_dev->interface_protocol = intf_desc->bInterfaceProtocol;
+
+ /* VID/PID */
+ cur_dev->vendor_id = dev_vid;
+ cur_dev->product_id = dev_pid;
+
+ /* Release Number */
+ cur_dev->release_number = desc.bcdDevice;
+
+ /* Interface Number */
+ cur_dev->interface_number = interface_num;
+ cur_dev->interface_class = intf_desc->bInterfaceClass;
+ cur_dev->interface_subclass = intf_desc->bInterfaceSubClass;
+ cur_dev->interface_protocol = intf_desc->bInterfaceProtocol;
+
+ } else
+ LOG("Can't open device 0x%.4x/0x%.4x during enumeration: %d\n", dev_vid, dev_pid, res);
}
}
} /* altsettings */