diff options
author | Tormod Volden <debian.tormod@gmail.com> | 2022-08-31 17:51:50 +0200 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2022-09-03 11:55:10 +0200 |
commit | 432bc0954db654bd732a67c9cdc14a2e47ee5fc4 (patch) | |
tree | 2a551be386f94fe55333ee615a4c79c95e6ab730 /libusb/core.c | |
parent | 2ca64b364ba8835bd4b12ce6ec86f5aec72bb9e4 (diff) | |
download | libusb-432bc0954db654bd732a67c9cdc14a2e47ee5fc4.tar.gz |
core: Avoid mutex lock while printing error and warning
Closes #1187
Reviewed-by: Dmitry Zakablukov <dimaz@passware.com>
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 8 |
1 files changed, 5 insertions, 3 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 |