Date: Tue, 09 Dec 2025 09:48:16 +0000 From: bugzilla-noreply@freebsd.org To: usb@FreeBSD.org Subject: [Bug 291506] libusb_open advisory lock (libusb compatiblity) Message-ID: <bug-291506-19105@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291506 Bug ID: 291506 Summary: libusb_open advisory lock (libusb compatiblity) Product: Base System Version: 15.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: usb Assignee: usb@FreeBSD.org Reporter: unitrunker@unitrunker.net Created attachment 266026 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=266026&action=edit Proposed patch Summary To more closely match behavior of libusb_open on other platforms, place an advisory lock on the device file descriptor. Currently, multiple processes can open the same USB device. On Linux and Windows, USB device enumeration omits devices currently in use. A number of ports assume this behavior. This proposed change will cause libusb_open to report an error (LIBUSB_ERROR_ACCESS) if it finds an advisory lock on the device. This includes a further change to libusb_open_with_vid_pid to skip over failed attempts to the first successful call to libusb_open. In an exteme case, this unexpected behavior in the FreeBSD implementation causes two ports to display the same device 32 times (see ports airspy and hydrasdr). As an example, a FreeBSD host has two USB devices attached that share the same VID/PID but different serial numbers. The intent is ... a. a first call to libusb_open_with_vid_pid returns a device handle to the first matching device - which the app keeps open. b. a second call to libusb_open_with_vid_pid returns a device handle to the second matching device (and not the first) - which the app keeps open. c. a third call to libusb_open_with_vid_pid returns null (and none of the other devices). libusb_close or process exit remove the advisory lock on the device. The specific advisory lock mechanism is flock(2). A complete patch is included. I will follow up with a test plan and the bits of code used for testing. -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-291506-19105>
