Skip to content

Commit

Permalink
darwin: locationID is 32-bit, not 64-bit
Browse files Browse the repository at this point in the history
Also zero-initialize locationID since otherwise it could be used
uninitialized.

Also change the return variable to bool, matching what the function
actually returns.

Fortunately, this only affected log messages.

Closes libusb#1412

[Tormod: Use PRIx32 for printing the 32-bit locationID]
Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
seanm authored and tormodvolden committed Jan 19, 2024
1 parent 5e4b389 commit b4f877f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions libusb/os/darwin_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,16 +629,16 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
struct darwin_cached_device *old_device;

io_service_t device;
UInt64 session, locationID;
int ret;

usbi_mutex_lock(&active_contexts_lock);

while ((device = IOIteratorNext (rem_devices)) != 0) {
bool is_reenumerating = false;

/* get the location from the i/o registry */
ret = get_ioregistry_value_number (device, CFSTR("sessionID"), kCFNumberSInt64Type, &session);
UInt64 session = 0;
bool ret = get_ioregistry_value_number (device, CFSTR("sessionID"), kCFNumberSInt64Type, &session);
UInt32 locationID = 0;
(void) get_ioregistry_value_number (device, CFSTR("locationID"), kCFNumberSInt32Type, &locationID);
IOObjectRelease (device);
if (!ret)
Expand All @@ -652,8 +652,8 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
if (old_device->in_reenumerate) {
/* device is re-enumerating. do not dereference the device at this time. libusb_reset_device()
* will deref if needed. */
usbi_dbg (NULL, "detected device detached due to re-enumeration. sessionID: 0x%" PRIx64 ", locationID: 0x%" PRIx64,
session, locationID);
usbi_dbg (NULL, "detected device detached due to re-enumeration. sessionID: 0x%" PRIx64
", locationID: 0x%" PRIx32, session, locationID);

/* the device object is no longer usable so go ahead and release it */
if (old_device->device) {
Expand Down Expand Up @@ -1287,7 +1287,7 @@ static enum libusb_error darwin_get_cached_device(struct libusb_context *ctx, io
usbi_mutex_lock(&darwin_cached_devices_mutex);
do {
list_for_each_entry(new_device, &darwin_cached_devices, list, struct darwin_cached_device) {
usbi_dbg(ctx, "matching sessionID/locationID 0x%" PRIx64 "/0x%x against cached device with sessionID/locationID 0x%" PRIx64 "/0x%x",
usbi_dbg(ctx, "matching sessionID/locationID 0x%" PRIx64 "/0x%" PRIx32 " against cached device with sessionID/locationID 0x%" PRIx64 "/0x%" PRIx32,
sessionID, locationID, new_device->session, new_device->location);
if (new_device->location == locationID && new_device->in_reenumerate) {
usbi_dbg (ctx, "found cached device with matching location that is being re-enumerated");
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11869
#define LIBUSB_NANO 11870

0 comments on commit b4f877f

Please sign in to comment.