scpi_usbtmc_libusb: set_configuration only if it is not already set

This avoids the issues described here:
http://libusb.sourceforge.net/api-1.0/caveats.html#configsel
This commit is contained in:
Aurelien Jacobs 2015-09-24 21:43:06 +02:00 committed by Uwe Hermann
parent e40e9ca28d
commit 938bdc25b7
1 changed files with 8 additions and 5 deletions

View File

@ -299,7 +299,7 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
struct libusb_config_descriptor *confdes;
const struct libusb_interface_descriptor *intfdes;
const struct libusb_endpoint_descriptor *ep;
int confidx, intfidx, epidx, config = 0;
int confidx, intfidx, epidx, config = 0, current_config;
uint8_t capabilities[24];
int ret, found = 0;
@ -367,11 +367,14 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
uscpi->detached_kernel_driver = 1;
}
if (libusb_get_configuration(usb->devhdl, &current_config) == 0
&& current_config != config) {
if ((ret = libusb_set_configuration(usb->devhdl, config)) < 0) {
sr_err("Failed to set configuration: %s.",
libusb_error_name(ret));
return SR_ERR;
}
}
if ((ret = libusb_claim_interface(usb->devhdl, uscpi->interface)) < 0) {
sr_err("Failed to claim interface: %s.",