darwin: Fix stale descriptor information post reset
authorIdo Yariv <ido@wizery.com>
Wed, 20 May 2020 20:23:11 +0000 (16:23 -0400)
committerChris Dickens <christopher.a.dickens@gmail.com>
Tue, 9 Jun 2020 17:28:41 +0000 (10:28 -0700)
As part of the recent removal of the backend get_device_descriptor()
function, the darwin backend was modified to update the cached
device_descriptor when a new device is processed. However, this wasn't
done for cases where the device is reused rather than allocated.
This could potentially result in getting stale data when using the
device following a reset.

In addition, when the device is reused, its session ID should be kept
up-to-date in the cached devices list, so it could be found in subsequent
resets.

Closes #733

Signed-off-by: Ido Yariv <ido@wizery.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/darwin_usb.c
libusb/version_nano.h

index 58944be255299cf390ba3cfad762670128d8bee6..ec5225ee716cb70a364ce6e560937a862853ea06 100644 (file)
@@ -1115,14 +1115,16 @@ static enum libusb_error process_new_device (struct libusb_context *ctx, struct
       dev->bus_number     = cached_device->location >> 24;
       assert(cached_device->address <= UINT8_MAX);
       dev->device_address = (uint8_t)cached_device->address;
-      static_assert(sizeof(dev->device_descriptor) == sizeof(cached_device->dev_descriptor),
-                    "mismatch between libusb and IOKit device descriptor sizes");
-      memcpy(&dev->device_descriptor, &cached_device->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
-      usbi_localize_device_descriptor(&dev->device_descriptor);
     } else {
       priv = usbi_get_device_priv(dev);
     }
 
+    static_assert(sizeof(dev->device_descriptor) == sizeof(cached_device->dev_descriptor),
+                  "mismatch between libusb and IOKit device descriptor sizes");
+    memcpy(&dev->device_descriptor, &cached_device->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
+    usbi_localize_device_descriptor(&dev->device_descriptor);
+    dev->session_data = cached_device->session;
+
     if (cached_device->parent_session > 0) {
       dev->parent_dev = usbi_get_device_by_session_id (ctx, (unsigned long) cached_device->parent_session);
     } else {
index 38dbc26128d1c00a84cf8df6205edb9714be62aa..cdfeb4b948d1f42f6a2de171aa903d44847a3765 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11516
+#define LIBUSB_NANO 11517