From: Aurelien Jacobs Date: Thu, 24 Sep 2015 19:43:06 +0000 (+0200) Subject: scpi_usbtmc_libusb: set_configuration only if it is not already set X-Git-Tag: libsigrok-0.4.0~192 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=938bdc25b766125350ba1fd46f5f95fdc813fb32;p=libsigrok.git 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 --- diff --git a/src/scpi/scpi_usbtmc_libusb.c b/src/scpi/scpi_usbtmc_libusb.c index 0b14cb3f..d7b7ef99 100644 --- a/src/scpi/scpi_usbtmc_libusb.c +++ b/src/scpi/scpi_usbtmc_libusb.c @@ -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,10 +367,13 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi) uscpi->detached_kernel_driver = 1; } - if ((ret = libusb_set_configuration(usb->devhdl, config)) < 0) { - sr_err("Failed to set configuration: %s.", - libusb_error_name(ret)); - return SR_ERR; + if (libusb_get_configuration(usb->devhdl, ¤t_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) {