- if (!drvc) {
- sr_err("Driver was not initialized.");
- return SR_ERR;
- }
- if (sdi->status != SR_ST_INACTIVE) {
- sr_err("Device already open.");
- return SR_ERR;
- }
-
- ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
- if (ret != SR_OK)
- return ret;
-
- ret = libusb_set_configuration(usb->devhdl, USB_CONFIG);
- if (ret != LIBUSB_SUCCESS) {
- sr_err("Failed to set USB configuration: %s.",
- libusb_error_name(ret));
- sr_usb_close(usb);
- return SR_ERR;
- }
-
- ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
- if (ret != LIBUSB_SUCCESS) {
- sr_err("Failed to claim interface: %s.",
- libusb_error_name(ret));
- sr_usb_close(usb);
- return SR_ERR;
- }
+ /* Try the whole shebang three times, fingers crossed. */
+ for (i = 0; i < 3; i++) {
+ ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
+ if (ret != SR_OK)
+ return ret;
+
+ ret = libusb_set_configuration(usb->devhdl, USB_CONFIG);
+ if (ret != LIBUSB_SUCCESS) {
+ sr_err("Failed to set USB configuration: %s.",
+ libusb_error_name(ret));
+ sr_usb_close(usb);
+ return SR_ERR;
+ }