From 71c1a0068fdb0273883096451db2bf1a0e7f4d2c Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Tue, 2 Dec 2014 10:03:38 +0900 Subject: [PATCH] Set USB configuration only if there are alternative ones This fixes USB3 issues for the epson and epson2 backends. Both these backends already made sure to send an even number of reads and writes but were affected nevertheless. It also solves USB3 issues with the third party epkowa backend. This one doesn't bother to ensure even counts of packets read and written. It works fine when this fix is applied (and it no longer clears halts w/o a stall condition). Note, there is no need to ensure even packet counts. --- sanei/sanei_usb.c | 109 ++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index 491ceebb8..c0fa74d0b 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -1379,30 +1379,32 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn) "configuration (%d), choosing first config (%d)\n", dev->descriptor.bNumConfigurations, dev->config[0].bConfigurationValue); - } - result = usb_set_configuration (devices[devcount].libusb_handle, - dev->config[0].bConfigurationValue); - if (result < 0) - { - SANE_Status status = SANE_STATUS_INVAL; - DBG (1, "sanei_usb_open: libusb complained: %s\n", usb_strerror ()); - if (errno == EPERM || errno == EACCES) + result = usb_set_configuration (devices[devcount].libusb_handle, + dev->config[0].bConfigurationValue); + if (result < 0) { - DBG (1, "Make sure you run as root or set appropriate " - "permissions\n"); - status = SANE_STATUS_ACCESS_DENIED; - } - else if (errno == EBUSY) - { - DBG (3, "Maybe the kernel scanner driver or usblp claims the " - "interface? Ignoring this error...\n"); - status = SANE_STATUS_GOOD; - } - if (status != SANE_STATUS_GOOD) - { - usb_close (devices[devcount].libusb_handle); - return status; + SANE_Status status = SANE_STATUS_INVAL; + + DBG (1, "sanei_usb_open: libusb complained: %s\n", + usb_strerror ()); + if (errno == EPERM || errno == EACCES) + { + DBG (1, "Make sure you run as root or set appropriate " + "permissions\n"); + status = SANE_STATUS_ACCESS_DENIED; + } + else if (errno == EBUSY) + { + DBG (3, "Maybe the kernel scanner driver or usblp claims the " + "interface? Ignoring this error...\n"); + status = SANE_STATUS_GOOD; + } + if (status != SANE_STATUS_GOOD) + { + usb_close (devices[devcount].libusb_handle); + return status; + } } } @@ -1443,13 +1445,13 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn) DBG (5, "sanei_usb_open: interface nr: %d\n", i); DBG (5, "sanei_usb_open: alt_setting nr: %d\n", a); - /* Start by interfaces found in sanei_usb_init */ - if (c == 0 && i != devices[devcount].interface_nr) - { - DBG (5, "sanei_usb_open: interface %d not detected as " - "a scanner by sanei_usb_init, ignoring.\n", i); - continue; - } + /* Start by interfaces found in sanei_usb_init */ + if (c == 0 && i != devices[devcount].interface_nr) + { + DBG (5, "sanei_usb_open: interface %d not detected as " + "a scanner by sanei_usb_init, ignoring.\n", i); + continue; + } interface = &dev->config[c].interface[i].altsetting[a]; @@ -1670,35 +1672,36 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn) "configuration (%d), choosing first config (%d)\n", desc.bNumConfigurations, config0->bConfigurationValue); - } - result = libusb_set_configuration (devices[devcount].lu_handle, - config0->bConfigurationValue); - libusb_free_config_descriptor (config0); + result = libusb_set_configuration (devices[devcount].lu_handle, + config0->bConfigurationValue); - if (result < 0) - { - SANE_Status status = SANE_STATUS_INVAL; + libusb_free_config_descriptor (config0); - DBG (1, "sanei_usb_open: libusb complained: %s\n", - sanei_libusb_strerror (result)); - if (result == LIBUSB_ERROR_ACCESS) + if (result < 0) { - DBG (1, "Make sure you run as root or set appropriate " - "permissions\n"); - status = SANE_STATUS_ACCESS_DENIED; - } - else if (result == LIBUSB_ERROR_BUSY) - { - DBG (3, "Maybe the kernel scanner driver or usblp claims the " - "interface? Ignoring this error...\n"); - status = SANE_STATUS_GOOD; - } + SANE_Status status = SANE_STATUS_INVAL; - if (status != SANE_STATUS_GOOD) - { - libusb_close (devices[devcount].lu_handle); - return status; + DBG (1, "sanei_usb_open: libusb complained: %s\n", + sanei_libusb_strerror (result)); + if (result == LIBUSB_ERROR_ACCESS) + { + DBG (1, "Make sure you run as root or set appropriate " + "permissions\n"); + status = SANE_STATUS_ACCESS_DENIED; + } + else if (result == LIBUSB_ERROR_BUSY) + { + DBG (3, "Maybe the kernel scanner driver or usblp claims " + "the interface? Ignoring this error...\n"); + status = SANE_STATUS_GOOD; + } + + if (status != SANE_STATUS_GOOD) + { + libusb_close (devices[devcount].lu_handle); + return status; + } } }