From 0003e606175e344d463a9af73658cab5c01d6286 Mon Sep 17 00:00:00 2001 From: Ido Yariv Date: Wed, 20 May 2020 16:23:11 -0400 Subject: darwin: Fix stale descriptor information post reset 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 Signed-off-by: Chris Dickens --- libusb/os/darwin_usb.c | 10 ++++++---- libusb/version_nano.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 58944be..ec5225e 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -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 { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 38dbc26..cdfeb4b 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11516 +#define LIBUSB_NANO 11517 -- cgit v1.2.1