aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb/libusb20.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-03-23 09:40:41 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-03-23 09:40:41 +0000
commitfd2ef04fdb3bac6e2fbcd02f380d1215716d06c5 (patch)
treef165c76a8e1954af570839d4040e5333bd21cf96 /lib/libusb/libusb20.c
parent266796e885807f714161259105e42fe1474e469d (diff)
downloadsrc-fd2ef04fdb3bac6e2fbcd02f380d1215716d06c5.tar.gz
src-fd2ef04fdb3bac6e2fbcd02f380d1215716d06c5.zip
Allow the libusb20_dev_get_port_path() function to be called when the
USB device is closed. This fixes a compatibility issue with upstream libusb. Found by: romain@ MFC after: 1 week
Notes
Notes: svn path=/head/; revision=331419
Diffstat (limited to 'lib/libusb/libusb20.c')
-rw-r--r--lib/libusb/libusb20.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index 1bad0ec16877..a83e725248ea 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -77,7 +77,6 @@ dummy_callback(struct libusb20_transfer *xfer)
#define dummy_check_connected (void *)dummy_int
#define dummy_set_power_mode (void *)dummy_int
#define dummy_get_power_mode (void *)dummy_int
-#define dummy_get_port_path (void *)dummy_int
#define dummy_get_power_usage (void *)dummy_int
#define dummy_kernel_driver_active (void *)dummy_int
#define dummy_detach_kernel_driver (void *)dummy_int
@@ -745,7 +744,26 @@ libusb20_dev_get_power_mode(struct libusb20_device *pdev)
int
libusb20_dev_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize)
{
- return (pdev->methods->get_port_path(pdev, buf, bufsize));
+
+ if (pdev->port_level == 0) {
+ /*
+ * Fallback for backends without port path:
+ */
+ if (bufsize < 2)
+ return (LIBUSB20_ERROR_OVERFLOW);
+ buf[0] = pdev->parent_address;
+ buf[1] = pdev->parent_port;
+ return (2);
+ }
+
+ /* check if client buffer is too small */
+ if (pdev->port_level > bufsize)
+ return (LIBUSB20_ERROR_OVERFLOW);
+
+ /* copy port number information */
+ memcpy(buf, pdev->port_path, pdev->port_level);
+
+ return (pdev->port_level); /* success */
}
uint16_t