Commit graph

12 commits

Author SHA1 Message Date
ShengYi Hung
9ca855653f 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
2025-07-21 02:15:58 -04:00
SHENGYI HUNG
4981b8968d libusb: consider bad fd as a broken event
Application can use libusb_get_pollfds to get pollfds from libusb then
close the fd themselves. This cause the hotplug thread unable to leave
because it will be consider as a invalid event then loop forever instead
of a broken event that should be quit immediately.

Reviewed by: bapt
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50959
2025-06-25 14:40:02 +02:00
SHENGYI HUNG
4acd63a626 libusb: Fix netlink sysevent multicast group name
Reviewed by:	hrs
Differential Revision: https://reviews.freebsd.org/D50739
2025-06-13 04:30:29 +09:00
SHENGYI HUNG
d285265918 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: 6c0ae1ab45/libusb/hotplug.c (L459)

Reviewed by:    bapt
Sponsored By:   FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50170
2025-05-08 14:20:21 -04:00
Baptiste Daroussin
a92ce19519 libusb: use the new snl_get_genl_mcast_group 2025-01-16 16:46:04 +01:00
Baptiste Daroussin
9dc96d8bc3 libusb: hotplug, use events instead of a timer when possible
Try to fetch events from nlsysevent or devd to determine when
to scan the usb bus for devices addition or removal.
if none are available fallback on the regular timer based (4s)
scanner

if devd socket or netlink socket is closed or error fallback on the
timer based method.

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D48300
2025-01-16 15:10:11 +01:00
Baptiste Daroussin
ba5834b8e1 libusb: fix hotplug sigbus
When a hotplug callback has been registered, and the program using
libusb is calling libusb_exit then the thread handler is set to
NO_THREAD which result in the variable controlling the loop the be set
to 0, it does a last pass through device available without having done
a scan, which result in a sigbus after it tried to unregister all the
devices.

directly break the loop instead and cleanup the list of devices

this fixes the tests with LGPLed libusb's hotplugtest program

MFC After:	3 days
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D48298
2025-01-04 11:20:49 +01:00
Warner Losh
2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Hans Petter Selasky
cca46c5e69 Add missing mutex unlock in failure case.
Differential Revision:	https://reviews.freebsd.org/D23430
Submitted by:	cem
Reported by:	Coverity
Coverity CID:	1368773
MFC after:	3 days
Sponsored by:	Mellanox Technologies
2020-01-30 17:30:04 +00:00
Hans Petter Selasky
a5b24a2b65 Only call libusb_hotplug_enumerate() once from libusb_hotplug_register_callback().
Else when registering multiple filters the same USB device may appear twice in
the list.

MFC after:	3 days
Sponsored by:	Mellanox Technologies
2019-06-26 12:04:54 +00:00
Hans Petter Selasky
a41b0ec143 Fix support for LIBUSB_HOTPLUG_ENUMERATE in libusb. Currently all
devices are enumerated regardless of of the LIBUSB_HOTPLUG_ENUMERATE
flag. Make sure when the flag is not specified no arrival events are
generated for currently enumerated devices.

MFC after:	3 days
Sponsored by:	Mellanox Technologies
2019-06-26 11:28:08 +00:00
Hans Petter Selasky
7bdc064b0b Implement libusb_hotplug_register_callback() and
libusb_hotplug_deregister_callback() for the LibUSB v1.0 API and
update the libusb(3) manual page.

Approved by:	re (kib)
Requested by:	swills
MFC after:	1 week
2016-06-22 10:38:41 +00:00