[sane-devel] sane to work with USB 3.0

Olaf Meeuwissen olaf.meeuwissen at avasys.jp
Tue Dec 2 04:13:54 UTC 2014

m. allan noah writes:

> Your patch makes no difference for the Fujitsu models in question.
> I'll commit the patch in the next couple days, after some more
> testing.

While working up a patch to only change the USB configuration if it is
not already current, I noticed my previous patch introduced a memory
leak with libusb-1.0.  Attached are my previous patch, a fix for the
memory leak and a change to the libusb-1.0 branch that only sets the USB
configuration if not already current.

I looked at doing the same for libusb-0.1 but that doesn't have the
convenience API to get the current configuration.  I am too lazy to
implement this using usb_control_message() myself for a library that I
consider obsolete (for a few years already ;-).

> allan
> On Mon, Dec 1, 2014 at 9:44 PM, m. allan noah <kitno455 at gmail.com> wrote:
>> Ha! As we speak, I am digging into USB3 again, because command
>> counting seems to not fix every case. I will try your patch and report
>> back.
>> allan
>> On Mon, Dec 1, 2014 at 9:21 PM, Olaf Meeuwissen
>> <olaf.meeuwissen at avasys.jp> wrote:
>>> Olaf Meeuwissen writes:
>>>> m. allan noah writes:
>>>>> I have added a USB3 port to my computer, and have spent a few days
>>>>> investigating this problem.
>>>> I haven't had that kind of time, yet :-(
>>> Finally got time to do so.
>>> # Someone managed to sky-rocket the priority of USB3 support to the top
>>> # of my TODO list ;-)
>>>>> It seems to be a bug in Linux kernel related to a bookkeeping error
>>>>> when the USB device is closed.  [...]
>>> Based on two days of looking at USB3 behaviour with three EPSON scanners
>>> and three backends, that does not seem to be the whole story.
>>>>> I have committed these changes to sane-backends git repo in
>>>>> 7a590f362e7e93979b706dd9e6ae34584e926ec3. If users of fujitsu scanners
>>>>> could try it out, I would appreciate any feedback. Note that this does
>>>>> not fix USB3 problems in other sane backends. Until the kernel is
>>>>> fixed, these types of repairs will have to be made on a per-backend
>>>>> basis, at the discretion of the maintainer.
>>> The epson and epson2 backends have been and still are using the kind of
>>> command counting and making sure to send an even count of reads and
>>> writes you added to the fujitsu backend.  That notwithstanding, they
>>> suffer from USB3 I/O problems with the Perfection V700 (GT-X900) and
>>> ES-H300 (GT-2500).  The epkowa backend does *not* even up the reads and
>>> writes and unsurprisingly shows the same problems.  In addition, the
>>> GT-D1000 (GT-1500), a non-free plugin needing device, is also affected.
>>> Making the epkowa backend even up the reads and writes did *not* fix the
>>> problem.  What did fix the problem for all three scanners and all three
>>> backends for me was a tiny change in sanei_usb.c.  With that change, the
>>> evening up of reads and writes was not needed either.
>>> The sanei_usb.c code unconditionally sets the USB configuration.  This
>>> happens even if the device has only one.  I found that *not* setting the
>>> USB configuration when there is only one fixed all my USB3 problems.  My
>>> understanding of the USB2 and USB3 standards is that the default USB
>>> configuration has to be set before devices become available to libusb.
>>> If that understanding is correct, then there is no need to set it unless
>>> you need a configuration that *differs* from the current one.  With only
>>> one configuration to choose from, there is then no need to set it.
>>> This patch does exactly that.  It skips setting the USB configuration if
>>> there is only one.  It should not break USB for any of the backends and
>>> *may* fix USB3 for all of them.
>>> Note: it may still set the default configuration if there are multiple
>>>       ones to choose from.  I have no devices I can test with to see if
>>>       that is problematic or not.  Even so, modifying the code to only
>>>       set a USB configuration if it differs should be safe.
>>>       # Patch is in preparation.
>>> Allan, can you locally revert your fujitsu fixes and try with the patch
>>> I applied?  Does that fix your USB3 issues?  Do you still need to even
>>> up the reads and writes?
>>> Unless it breaks things for you, could you please commit my patch?
>>> # Even if it does not fix USB3 for you.
>>> Other people with USB3 issues are of course more than welcome to try
>>> this patch too!
>>>> [...]

Hope this helps,
Olaf Meeuwissen, LPIC-2           FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962               Help support software freedom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Set-USB-configuration-only-if-there-are-alternative-.patch
Type: text/x-diff
Size: 5587 bytes
Desc: Set USB configuration only if there are alternative ones
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20141202/4e9a8908/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-memory-leak-w-libusb-1.0-introduced-in-9b99304.patch
Type: text/x-diff
Size: 1183 bytes
Desc: Fix memory leak w/ libusb-1.0 (introduced in 9b99304)
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20141202/4e9a8908/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Set-USB-configuration-only-if-different-from-the-cur.patch
Type: text/x-diff
Size: 1096 bytes
Desc: Set USB configuration only if different from the current one
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20141202/4e9a8908/attachment-0002.patch>

More information about the sane-devel mailing list