git: 9ca855653f32 - main - libusb: implement libusb_hotplug_get_user_data
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 21 Jul 2025 06:17:14 UTC
The branch main has been updated by aokblast:
URL: https://cgit.FreeBSD.org/src/commit/?id=9ca855653f32605f266e5e457581ec3e68fd4ff9
commit 9ca855653f32605f266e5e457581ec3e68fd4ff9
Author: ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2025-07-09 08:30:52 +0000
Commit: ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2025-07-21 06:15:58 +0000
libusb: implement libusb_hotplug_get_user_data
libusb provides a function to get the callback userdata for a given
callback since this structure is opaque to libusb user.
Approved by: markj (mentor), lwhsu (mentor)
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D51223
---
lib/libusb/libusb.3 | 5 +++++
lib/libusb/libusb.h | 2 ++
lib/libusb/libusb10_hotplug.c | 18 ++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index da927f8985a8..2e2ac8b1e98b 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -781,6 +781,11 @@ This function unregisters a hotplug filter.
This function releases the memory storage in
.Fa pollfds ,
and is safe to call when the argument is NULL.
+.Pp void *
+.Fn libusb_hotplug_get_user_data "struct libusb_context *ctx" "libusb_hotplug_callback_handle callback_handle"
+This function returns the user data from the opaque
+.Fa callback_handle ,
+or returns NULL if no matching handle is found.
.Sh LIBUSB VERSION 0.1 COMPATIBILITY
The library is also compliant with LibUSB version 0.1.12.
.Pp
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 1962152c0b68..520b81da3a75 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -594,6 +594,8 @@ typedef int (*libusb_hotplug_callback_fn)(libusb_context *ctx,
int libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *handle);
void libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle handle);
+void *libusb_hotplug_get_user_data(struct libusb_context *ctx,
+ libusb_hotplug_callback_handle callback_handle);
/* Streams support */
diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c
index 369539d4512e..9c46d4926bfa 100644
--- a/lib/libusb/libusb10_hotplug.c
+++ b/lib/libusb/libusb10_hotplug.c
@@ -414,3 +414,21 @@ void libusb_hotplug_deregister_callback(libusb_context *ctx,
free(handle);
}
+
+void *
+libusb_hotplug_get_user_data(struct libusb_context *ctx,
+ libusb_hotplug_callback_handle callback_handle)
+{
+ libusb_hotplug_callback_handle handle;
+
+ ctx = GET_CONTEXT(ctx);
+
+ HOTPLUG_LOCK(ctx);
+ TAILQ_FOREACH(handle, &ctx->hotplug_cbh, entry) {
+ if (handle == callback_handle)
+ break;
+ }
+ HOTPLUG_UNLOCK(ctx);
+
+ return (handle);
+}