Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libusb_init() fails with LIBUSB_ERROR_IO on Android if there are no devices attached #301

Closed
matswebjorn opened this issue May 21, 2017 · 0 comments
Labels

Comments

@matswebjorn
Copy link

matswebjorn commented May 21, 2017

I'm using libusb 1.0.21 with a Samsung SM-T580 (Android 6.0.1 API23) rooted tablet. If I have at least one external device attached to the bus then libusb_init()returns ok, but if there aren't any external devices attached, then libusb_init() fails with LIBUSB_ERROR_IO.

The call chain is

libusb_init: usbi_backend->init()
    op_init:linux_scan_devices()
        linux_scan_devices:linux_default_scan_devices()
            linux_default_scan_devices:sysfs_get_device_list()
                sysfs_get_device_list()

The reason is that when there aren't any devices attached, then readdir(devices) in sysfs_get_device_list() just returns two entries "." and ".." and this is considered an IO-error.

But if I attach a single device then readdir(devices) returns ".", "..", "1-1", "usb1", "usb2", "1-0:1.0", "1-1:1.0" and "2-0:1.0". This is an OTG device so it might explain why no devices (even no root hub) are reported when no external devices are attached.

But shouldn't it be allowed to initialize libusb even if there are no devices on the bus, or if this is an OTG device?

@mcuee mcuee added the android label Sep 10, 2017
seanm pushed a commit to seanm/libusb that referenced this issue Dec 29, 2017
When using sysfs to scan for devices, libusb_init() will fail if there
are no USB devices present. There is no reason for this behavior, so
this commit modifies the logic to only return an error if one or more
devices are present but none could be successfully enumerated.

Closes libusb#301

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Seneral pushed a commit to Seneral/libusb that referenced this issue Sep 21, 2021
When using sysfs to scan for devices, libusb_init() will fail if there
are no USB devices present. There is no reason for this behavior, so
this commit modifies the logic to only return an error if one or more
devices are present but none could be successfully enumerated.

Closes libusb#301

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants