From 4b5ecec817481bc064b9fb6c9487ecff22fa70ca Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Fri, 13 Sep 2013 19:56:07 +0000 Subject: [PATCH] Submitted by Stephen Roe: patch #7710: usb_libusb: Check VID/PID before opening device * usb_libusb.c (usbdev_open): Swap the sequence of verifying the VID:PID, and opening the device. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@1228 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/ChangeLog | 7 +++++++ avrdude/NEWS | 9 +++++---- avrdude/usb_libusb.c | 18 +++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/avrdude/ChangeLog b/avrdude/ChangeLog index 1bdf5da0..ac7a93a1 100644 --- a/avrdude/ChangeLog +++ b/avrdude/ChangeLog @@ -1,3 +1,10 @@ +2013-09-13 Joerg Wunsch + + Submitted by Stephen Roe: + patch #7710: usb_libusb: Check VID/PID before opening device + * usb_libusb.c (usbdev_open): Swap the sequence of verifying the + VID:PID, and opening the device. + 2013-09-13 Joerg Wunsch patch #8176: butterfly.c (AVR109 protocol implementation) clean-up and bug-fixing diff --git a/avrdude/NEWS b/avrdude/NEWS index 9cb179b3..c2808a1f 100644 --- a/avrdude/NEWS +++ b/avrdude/NEWS @@ -107,10 +107,11 @@ Current: - bug #28344: chip_erase_delay too short for ATmega324P, 644, 644P, and 1284P - bug #34277: avrdude reads wrong byte order if using avr911 (aka butterfly) - bug #35456: The progress bar for STK500V2 programmer is "wrong". - - patch #5708 avrdude should make 10 synchronization attempts instead of just one - - patch #7606 ATtiny43u support - - patch #7657 Add ATmega406 support for avrdude using DRAGON + JTAG - - bug #35474 Feature request: print fuse values in safemode output. + - patch #5708: avrdude should make 10 synchronization attempts instead of just one + - patch #7606: ATtiny43u support + - patch #7657: Add ATmega406 support for avrdude using DRAGON + JTAG + - bug #35474: Feature request: print fuse values in safemode output. + - patch #7710: usb_libusb: Check VID/PID before opening device * Keep track of input file contents diff --git a/avrdude/usb_libusb.c b/avrdude/usb_libusb.c index 22570fb2..8f3b0498 100644 --- a/avrdude/usb_libusb.c +++ b/avrdude/usb_libusb.c @@ -115,11 +115,11 @@ static int usbdev_open(char * port, long baud, union filedescriptor *fd) { 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) + udev = usb_open(dev); + if (udev) { /* yeah, we found something */ if (usb_get_string_simple(udev, @@ -246,10 +246,14 @@ static int usbdev_open(char * port, long baud, union filedescriptor *fd) fd->usb.max_xfer = dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize; } } - return 0; + return 0; + trynext: + usb_close(udev); } - trynext: - usb_close(udev); + else + fprintf(stderr, + "%s: usbdev_open(): cannot open device: %s\n", + progname, usb_strerror()); } } }