From 432bc0954db654bd732a67c9cdc14a2e47ee5fc4 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Wed, 31 Aug 2022 17:51:50 +0200 Subject: core: Avoid mutex lock while printing error and warning Closes #1187 Reviewed-by: Dmitry Zakablukov Signed-off-by: Tormod Volden --- libusb/core.c | 8 +++++--- libusb/version_nano.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 5951816..d4f4d9f 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1398,20 +1398,22 @@ static void do_close(struct libusb_context *ctx, for_each_transfer_safe(ctx, itransfer, tmp) { struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); + uint32_t state_flags; if (transfer->dev_handle != dev_handle) continue; usbi_mutex_lock(&itransfer->lock); - if (!(itransfer->state_flags & USBI_TRANSFER_DEVICE_DISAPPEARED)) { + state_flags = itransfer->state_flags; + usbi_mutex_unlock(&itransfer->lock); + if (!(state_flags & USBI_TRANSFER_DEVICE_DISAPPEARED)) { usbi_err(ctx, "Device handle closed while transfer was still being processed, but the device is still connected as far as we know"); - if (itransfer->state_flags & USBI_TRANSFER_CANCELLING) + if (state_flags & USBI_TRANSFER_CANCELLING) usbi_warn(ctx, "A cancellation for an in-flight transfer hasn't completed but closing the device handle"); else usbi_err(ctx, "A cancellation hasn't even been scheduled on the transfer for which the device is closing"); } - usbi_mutex_unlock(&itransfer->lock); /* remove from the list of in-flight transfers and make sure * we don't accidentally use the device handle in the future diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 173c4f9..dd859e7 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11743 +#define LIBUSB_NANO 11744 -- cgit v1.2.1