I doesn't fix any problems but I think it is nicer code. :-)
I don't think we want to call usb_detach_kernel_driver_np unless we
claimed the device.
$ diff -uw libusb.c.bak libusb.c.new
--- libusb.c.bak 2010-05-11 09:35:39.000000000 -0400
+++ libusb.c.new 2010-05-11 09:32:44.000000000 -0400
@@ -206,18 +206,21 @@
upsdebugx(2, "failed to claim USB
device: %s", usb_strerror());
+ if (retries-- > 1) {
+ continue;
+ }
+
+ fatalx(EXIT_FAILURE, "Can't claim USB
device [%04x:%04x]: %s", curDevice->VendorID, curDevice->ProductID,
usb_strerror());
+ }
+
+ if (retries > 1) {
if (usb_detach_kernel_driver_np(udev,
0) < 0) {
upsdebugx(2, "failed to detach
kernel driver from USB device: %s", usb_strerror());
} else {
upsdebugx(2, "detached kernel
driver from USB device...");
}
-
- if (retries-- > 0) {
- continue;
}
- fatalx(EXIT_FAILURE, "Can't claim USB
device [%04x:%04x]: %s", curDevice->VendorID, curDevice->ProductID,
usb_strerror());
- }
#else
if (usb_claim_interface(udev, 0) < 0) {
fatalx(EXIT_FAILURE, "Can't claim USB
device [%04x:%04x]: %s", curDevice->VendorID, curDevice->ProductID,
usb_strerror());
Charles Lepple
2010-May-11 22:59 UTC
[Nut-upsdev] possible code change to drivers/libusb.c
On Tue, May 11, 2010 at 10:10 AM, James <bjlockie at lockie.ca> wrote:> ?I doesn't fix any problems but I think it is nicer code. :-) > I don't think we want to call usb_detach_kernel_driver_np unless we claimed > the device.Actually, we want to call usb_detach_kernel_driver_np() if we *can't* claim the device, because that usually means that the kernel usbhid driver has claimed it already (and it needs to be detached). If we still can't claim it after that, then it is usually a permissions problem. -- - Charles Lepple