Yubico / yubikey-personalization

YubiKey Personalization cross-platform library and tool
https://developers.yubico.com/yubikey-personalization/
BSD 2-Clause "Simplified" License
300 stars 82 forks source link

detach kernel driver only if kernel driver is active #52

Closed eworm-de closed 10 years ago

klali commented 10 years ago

under what circumstances do you hit this? if the driver is already detached manually? should we do something similar for the libusb 0.1 backend?

eworm-de commented 10 years ago

I am chasing another issue (that is probably related to usbhid module) and found this to be a theoretical problem.

libusb_detach_kernel_driver() may return LIBUSB_ERROR_NOT_FOUND in case no kernel drivers was active. So the alternative would be to check for (ykl_errno != 0 && ykl_errno != LIBUSB_ERROR_NOT_FOUND) in error condition, no? Or is it expected to goto done and not call libusb_set_configuration() in this case?

klali commented 10 years ago

I'd say that noone considered the case properly.. Never seen it happen though, but I guess we should try to handle it correctly, question is what correctly means here.

eworm-de commented 10 years ago

My personal feeling is to avoid LIBUSB_ERROR_NOT_FOUND and check for kernel driver before. Probably anybody had the same in mind when implementing libusb_kernel_driver_active(). ;)

I'd be fine to declare LIBUSB_ERROR_NOT_FOUND a good return value, though. But IMHO the actualy code - although it works well in most cases as having usbhid around is pretty common - is not correct.

klali commented 10 years ago

about to merge this, thanks for the contribution!

/klas