git: d28526591803 - main - libusb: Emit event after deregistering hotplug handler

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 08 May 2025 18:20:49 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=d2852659180307475a8376ce86aa587cccbb10bf

commit d2852659180307475a8376ce86aa587cccbb10bf
Author:     SHENGYI HUNG <aokblast@FreeBSD.org>
AuthorDate: 2025-05-05 17:52:45 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-05-08 18:20:21 +0000

    libusb: Emit event after deregistering hotplug handler
    
    The original implementation did not emit an event when a hotplug handler
    was deregistered. This omission causes issues for programs that follow
    the best practices recommended by libusb—particularly those that use
    `libusb_hotplug_register_callback()` or similar functions in a loop
    while managing hotplug handlers dynamically.
    
    Without emitting an event after deregistration, these programs can
    become stuck waiting indefinitely for an event that will never come,
    as the condition to break out of the wait loop is never satisfied.
    
    See: https://github.com/libusb/libusb/blob/6c0ae1ab456da49e7805115e77ce0428ace4ea41/libusb/hotplug.c#L459
    
    Reviewed by:    bapt
    Sponsored By:   FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D50170
---
 lib/libusb/libusb10_hotplug.c | 1 +
 lib/libusb/libusb10_io.c      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c
index b7573bf916ec..1e8037da1bd4 100644
--- a/lib/libusb/libusb10_hotplug.c
+++ b/lib/libusb/libusb10_hotplug.c
@@ -407,6 +407,7 @@ void libusb_hotplug_deregister_callback(libusb_context *ctx,
 
 	HOTPLUG_LOCK(ctx);
 	TAILQ_REMOVE(&ctx->hotplug_cbh, handle, entry);
+	libusb_interrupt_event_handler(ctx);
 	HOTPLUG_UNLOCK(ctx);
 
 	free(handle);
diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c
index 59bac60c4672..2790142486ba 100644
--- a/lib/libusb/libusb10_io.c
+++ b/lib/libusb/libusb10_io.c
@@ -231,6 +231,7 @@ do_done:
 
 	/* Wakeup other waiters */
 	pthread_cond_broadcast(&ctx->ctx_cond);
+	DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb10_handle_events_sub complete");
 
 	return (err);
 }