[Nut-upsdev] possible code change to drivers/libusb.c

James bjlockie at lockie.ca
Tue May 11 14:10:02 UTC 2010


  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());



More information about the Nut-upsdev mailing list