avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avrdude-dev] PATCH: Only open USB device after the correct vendor/produ


From: Stephen Roe
Subject: [avrdude-dev] PATCH: Only open USB device after the correct vendor/product ID has been identified
Date: Tue, 24 Jan 2012 18:38:09 +0000

When connecting to a USB device the function usbdev_open in
usb_libusb.c iterates through the usb buses and devices to find the
device that matches the required vendor and product id.

In this function the usb device if first opened before the the vendor
and product id is checked.  This is not necessary and causes warnings
to be printed to stderr for every usb device that is tried before the
required device is found if the current user does not have permissions
for that particular device.

The vendor and product id are available for each device on the buses
without first opening them.  Therefore by placing the vendor and
product id check before opening the device removes the warnings that
are printed to stderr.

Please see the below patch that corrects this behaviour.  I have built
and tested this against the 5.11 tarball.

    --Stephen


--- usb_libusb.c.orig   2011-09-15 15:37:05.000000000 +0100
+++ usb_libusb.c        2012-01-24 18:27:48.783394765 +0000
@@ -107,14 +107,14 @@
     {
       for (dev = bus->devices; dev; dev = dev->next)
        {
-         udev = usb_open(dev);
-         if (udev)
+         if (dev->descriptor.idVendor == USB_VENDOR_ATMEL &&
+             dev->descriptor.idProduct == (unsigned short)baud)
            {
-             if (dev->descriptor.idVendor == USB_VENDOR_ATMEL &&
-                 dev->descriptor.idProduct == (unsigned short)baud)
-               {
-                 /* yeah, we found something */
-                 if (usb_get_string_simple(udev,
+             /* yeah, we found something */
+             udev = usb_open(dev);
+             if (udev)
+               {
+                 if (usb_get_string_simple(udev,
                                            dev->descriptor.iSerialNumber,
                                            string, sizeof(string)) < 0)
                    {
@@ -221,9 +221,10 @@
                      fd->usb.ep = USBDEV_BULK_EP_READ;
                    }
                   return 0;
+
+                  trynext:
+                 usb_close(udev);
                }
-             trynext:
-             usb_close(udev);
            }
        }
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]