Search code examples
libusb-1.0

libusb doesn't enumerate a device if cleanup failed in previous program execution. Can I prevent this, or recover from the bad state in software?


I have code that opens a libusb device, does some asynchronous transfers, and then quits. Sometimes the cleanup code at the end works out and I can re-run the program without problems, but other times libusb_cancel_transfer returns LIBUSB_ERROR_PIPE and thereafter the device does not appear in the list returned by libusb_get_device_list in any subsequent execution of the program.

The problem can be recovered from by unplugging the device and reinserting into the same port, but that's not acceptable. I need at the very least some way to recover from the bad state in software, but ideally this shouldn't ever happen.

In case this problem could be platform related, I'm running MacOSX 10.9.5 and the program is C++ built with the llvm compiler.


Solution

  • I have discovered that I was inadvertently submitting control transfers whose setup packets were uninitialized memory. (Used the wrong size constant.) When I stopped doing that, the problem no longer occurred.