Page MenuHomeFreeBSD

libusb: implement libusb_set_option
Needs ReviewPublic

Authored by aokblast on Jun 12 2025, 4:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 7:13 PM
Unknown Object (File)
Sat, Sep 27, 5:00 PM
Unknown Object (File)
Fri, Sep 19, 11:42 AM
Unknown Object (File)
Thu, Sep 18, 3:11 PM
Unknown Object (File)
Mon, Sep 15, 11:45 PM
Unknown Object (File)
Sun, Sep 14, 10:51 AM
Unknown Object (File)
Sep 12 2025, 9:52 AM
Unknown Object (File)
Sep 11 2025, 1:57 PM

Details

Reviewers
bapt
Group Reviewers
USB
manpages
Summary

Implement libusb_set_option for API compatibility of libusb upstream
The implementation status of each option is as following:

LIBUSB_OPTION_LOG_LEVEL: just like libusb_set_debug
LIBUSB_OPTION_LOG_CB: add callback support for DPRINTF
LIBUSB_OPTION_NO_DEVICE_DISCOVERY: disable initialization of devd and
netlink when register. Also, create no thread when registration of
callback happens.
LIBUSB_OPTION_USE_USBDK: no needed as USBDK is for Windows

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 66157
Build 63040: arc lint + arc unit

Event Timeline

The change about DEBUG_LEVEL to LOG_LEVEL is required to allow set_debug and debug callback works. So add that patch as a parent.

kevans added inline comments.
lib/libusb/libusb10.c
296

log_level seems to be unused in this final version, can it be removed?

1886

style(9) dictates explicit comparison against NULL here

lib/libusb/libusb10_hotplug.c
387

Is there some implication here for no_discovery? Should this be reachable at all if it's set?

lib/libusb/libusb10_hotplug.c
387

The no_discovery in upstream libusb is utilized when init the context. It will not start any hotplug scan thread if this option is true on the upstream libusb. That means this option is useless after libusb_init is called.

However, our implementation on the hotplug scan thread starts when the hotplug register is called instead of the libusb_init. I think the time point of no_discovery on upstream libusb is tighter because after init it will not work. So our implementation to do check on hotplug handler won't break any usecase of this option as it is expected to be set before init the context and actually hotplug register should be called after init.

lib/libusb/libusb10.c
296

It is a miss. Sorry, I will update a newer version later.

commit message ought to reference libusb_set_option not just add option

lib/libusb/libusb.h
278

This probably calls for a comment explaining why the value is reused (was already true before your changes)

lib/libusb/libusb.h
278

The upstream code change in here: https://github.com/libusb/libusb/commit/33d9949921423d0911527e04af8372d320f2489b.

They first use LIBUSB_OPTION_NO_DEVICE_DISCOVERY to replace LIBUSB_OPTION_WEAK_AUTHORITY. Then for the compatibility, they define LIBUSB_OPTION_WEAK_AUTHORITY as a macro again. I would send a different patch about this.

aokblast retitled this revision from libusb: add option to libusb: implement libusb_set_option.Aug 5 2025, 12:47 PM

Rebase to main and remove unrelated changes