continue;
for (j = 0; j < ARRAY_SIZE(supported_devices); j++) {
- if (desc.idVendor == supported_devices[j].vendor_id
- && desc.idProduct == supported_devices[j].product_id) {
+ if (desc.idVendor == supported_devices[j].vendor_id &&
+ desc.idProduct == supported_devices[j].product_id) {
if (op == SCAN_OP_BUILD_DEVLIST) {
am7xxx_device *new_device;
goto out;
}
- libusb_set_configuration((*dev)->usb_device, 2);
- libusb_claim_interface((*dev)->usb_device, 0);
+ /* XXX, the device is now open, if any
+ * of the calls below fail we need to
+ * close it again before bailing out.
+ */
+
+ ret = libusb_set_configuration((*dev)->usb_device, 2);
+ if (ret < 0) {
+ debug(ctx, "libusb_set_configuration failed\n");
+ debug(ctx, "Cannot set configuration 2\n");
+ goto out_libusb_close;
+ }
+
+ ret = libusb_claim_interface((*dev)->usb_device, 0);
+ if (ret < 0) {
+ debug(ctx, "libusb_claim_interface failed\n");
+ debug(ctx, "Cannot claim interface 0\n");
+out_libusb_close:
+ libusb_close((*dev)->usb_device);
+ (*dev)->usb_device = NULL;
+ goto out;
+ }
+
goto out;
}
current_index++;