Hi, everybody,
I have a suggestion about the loop termination condition of
jtag_libusb_match().
I think the condition should use "logical or" instead of "logical and".
The reason is the termination condition is used to detect the end of
vids/pids array.
The end of vids/pids array should "both" be zero. So, it should use
"logical or"
instead of "logical and".
There is a potential bug if to use "logical and" in the condition. If some
device has
non-zero vid, but zero pid, openocd will not be able to detect the device
even the
device is a correct one.
Following is the diff after my modification.
diff --git a/src/jtag/drivers/libusb0_common.c
b/src/jtag/drivers/libusb0_common.c
index c731ee5..84dd688 100644
--- a/src/jtag/drivers/libusb0_common.c
+++ b/src/jtag/drivers/libusb0_common.c
@@ -28,7 +28,7 @@
static bool jtag_libusb_match(struct jtag_libusb_device *dev,
const uint16_t vids[], const uint16_t pids[])
{
- for (unsigned i = 0; vids[i] && pids[i]; i++) {
+ for (unsigned i = 0; vids[i] || pids[i]; i++) {
if (dev->descriptor.idVendor == vids[i] &&
dev->descriptor.idProduct == pids[i]) {
return true;
diff --git a/src/jtag/drivers/libusb1_common.c
b/src/jtag/drivers/libusb1_common.c
index 194f737..9256267 100644
--- a/src/jtag/drivers/libusb1_common.c
+++ b/src/jtag/drivers/libusb1_common.c
@@ -33,7 +33,7 @@ static bool jtag_libusb_match(struct jtag_libusb_device
*dev,
{
struct libusb_device_descriptor dev_desc;
- for (unsigned i = 0; vids[i] && pids[i]; i++) {
+ for (unsigned i = 0; vids[i] || pids[i]; i++) {
if (libusb_get_device_descriptor(dev, &dev_desc) == 0) {
if (dev_desc.idVendor == vids[i] &&
dev_desc.idProduct == pids[i])
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel