summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2011-02-22 15:45:51 +0000
committerPete Batard <pbatard@gmail.com>2011-02-22 15:45:51 +0000
commit9dc299236c4f9e58b7281a035a8c35c0cd33e1a3 (patch)
tree10a343204dc9fbd160d07962eee205ffb97b9480
parent315216385fccd1421e42698a18fa8239d32b3ba8 (diff)
downloadlibusb-pbr330.tar.gz
fixed libusb_get_port_path using zombie parentspbr330
* add a call to libusb_get_device_list to ensure the parents exist * modified API as a context is required for get_device_list
-rw-r--r--configure.ac2
-rw-r--r--examples/xusb.c2
-rw-r--r--libusb/core.c10
-rw-r--r--libusb/libusb.h2
-rw-r--r--libusb/libusb_version.h2
5 files changed, 13 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 302f439..191b300 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
m4_define(LIBUSB_MAJOR, [1])
m4_define(LIBUSB_MINOR, [0])
m4_define(LIBUSB_MICRO, [8])
-m4_define(LIBUSB_NANO, [10329])
+m4_define(LIBUSB_NANO, [10330])
AC_INIT([libusb], LIBUSB_MAJOR.LIBUSB_MINOR.LIBUSB_MICRO, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
diff --git a/examples/xusb.c b/examples/xusb.c
index b1bfa39..ed69f5a 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -630,7 +630,7 @@ int test_device(uint16_t vid, uint16_t pid)
dev = libusb_get_device(handle);
bus = libusb_get_bus_number(dev);
- r = libusb_get_port_path(dev, port_path, sizeof(port_path));
+ r = libusb_get_port_path(NULL, dev, port_path, sizeof(port_path));
if (r > 0) {
printf("bus: %d, port path from HCD: %d", bus, port_path[0]);
for (i=1; i<r; i++) {
diff --git a/libusb/core.c b/libusb/core.c
index 0e9f357..f09c6cd 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -690,9 +690,16 @@ uint8_t API_EXPORTED libusb_get_port_number(libusb_device *dev)
* \returns the number of elements filled
* \returns LIBUSB_ERROR_OVERFLOW if the array is too small
*/
-int API_EXPORTED libusb_get_port_path(libusb_device *dev, uint8_t* path, uint8_t path_len)
+int API_EXPORTED libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_len)
{
int i = path_len;
+ ssize_t r;
+ struct libusb_device **devs;
+
+ /* The device needs to be open, else the parents may have been destroyed */
+ r = libusb_get_device_list(ctx, &devs);
+ if (r < 0)
+ return (int)r;
while(dev) {
// HCDs can be listed as devices and would have port #0
@@ -706,6 +713,7 @@ int API_EXPORTED libusb_get_port_path(libusb_device *dev, uint8_t* path, uint8_t
path[i] = dev->port_number;
dev = dev->parent_dev;
}
+ libusb_free_device_list(devs, 1);
memmove(path, &path[i], path_len-i);
return path_len-i;
}
diff --git a/libusb/libusb.h b/libusb/libusb.h
index ba3d5f5..4719dd1 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -890,7 +890,7 @@ void LIBUSB_CALL libusb_free_config_descriptor(
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
-int LIBUSB_CALL libusb_get_port_path(libusb_device *dev, uint8_t* path, uint8_t path_length);
+int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
unsigned char endpoint);
diff --git a/libusb/libusb_version.h b/libusb/libusb_version.h
index fc2c2b2..edcf85b 100644
--- a/libusb/libusb_version.h
+++ b/libusb/libusb_version.h
@@ -24,6 +24,6 @@
#define LIBUSB_VERSION_MAJOR 1
#define LIBUSB_VERSION_MINOR 0
#define LIBUSB_VERSION_MICRO 8
-#define LIBUSB_VERSION_NANO 10329
+#define LIBUSB_VERSION_NANO 10330
#endif