summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2016-05-29 17:35:09 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2016-05-29 17:35:09 -0700
commit0b947e5f9b2dfffa4def7007f4fb5b23fe2eb05f (patch)
tree33255352b28cd4f4c83208404bd746d4d4d7a68b
parent578942b5a90cd36b47b11e0992c2e92a05b70d91 (diff)
downloadlibusb-0b947e5f9b2dfffa4def7007f4fb5b23fe2eb05f.tar.gz
Windows: Fix false assertion failure message during enumeration
Commit 1d54ee1b6687c532eca75925f56eb12e2a34ce42 addressed a device reference leak but introduced a false warning message that occurs for devices detected in early enumeration passes (e.g. hubs). The assertion is meant to warn of a mismatch between parent devices but fails to account for the fact that some devices that are allocated early do not have a parent device assigned until the later enumeration passes. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--libusb/os/windows_winusb.c19
-rw-r--r--libusb/os/windows_winusb.h4
-rw-r--r--libusb/version_nano.h2
3 files changed, 15 insertions, 10 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 9fe2956..082e846 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -1514,16 +1514,20 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
if (dev == NULL)
LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
- windows_device_priv_init(dev);
+ priv = windows_device_priv_init(dev);
} else {
usbi_dbg("found existing device for session [%lX] (%u.%u)",
session_id, dev->bus_number, dev->device_address);
- if (_device_priv(dev)->parent_dev != parent_dev) {
- usbi_err(ctx,"program assertion failed - existing device should share parent");
- } else {
- // We hold a reference to parent_dev instance, but this device already
- // has a parent_dev reference (only one per child)
- libusb_unref_device(parent_dev);
+
+ priv = _device_priv(dev);
+ if (priv->parent_dev != NULL) {
+ if (priv->parent_dev != parent_dev) {
+ usbi_err(ctx, "program assertion failed - existing device should share parent");
+ } else {
+ // We hold a reference to parent_dev instance, but this device already
+ // has a parent_dev reference (only one per child)
+ libusb_unref_device(parent_dev);
+ }
}
}
@@ -1537,7 +1541,6 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
}
}
- priv = _device_priv(dev);
}
// Setup device
diff --git a/libusb/os/windows_winusb.h b/libusb/os/windows_winusb.h
index 303f4a6..49c1df5 100644
--- a/libusb/os/windows_winusb.h
+++ b/libusb/os/windows_winusb.h
@@ -224,7 +224,7 @@ static inline struct windows_device_priv *_device_priv(struct libusb_device *dev
return (struct windows_device_priv *)dev->os_priv;
}
-static inline void windows_device_priv_init(struct libusb_device *dev)
+static inline struct windows_device_priv *windows_device_priv_init(struct libusb_device *dev)
{
struct windows_device_priv *p = _device_priv(dev);
int i;
@@ -247,6 +247,8 @@ static inline void windows_device_priv_init(struct libusb_device *dev)
p->usb_interface[i].endpoint = NULL;
p->usb_interface[i].restricted_functionality = false;
}
+
+ return p;
}
static inline void windows_device_priv_release(struct libusb_device *dev)
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 795d2bc..b92475f 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11108
+#define LIBUSB_NANO 11109