Page MenuHomeFreeBSD

usb: preserve error when doing request
Needs ReviewPublic

Authored by aokblast on Aug 29 2025, 5:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 9, 2:57 PM
Unknown Object (File)
Thu, Oct 9, 2:57 PM
Unknown Object (File)
Thu, Oct 9, 2:57 PM
Unknown Object (File)
Thu, Oct 9, 1:51 PM
Unknown Object (File)
Mon, Sep 29, 2:58 AM
Unknown Object (File)
Sun, Sep 28, 3:46 PM
Unknown Object (File)
Sun, Sep 28, 1:19 AM
Unknown Object (File)
Thu, Sep 25, 12:42 PM
Subscribers

Details

Reviewers
None
Group Reviewers
USB
Summary

Currently, USB request not distinguished different error and always return EIO.
However, some error are recoverable or ignorable in userspace.
Therefore, we preserve the meaning of different error to userspace then
allow userspace to decide how to use the return error.

For example, when host required a vendor defined descriptor but the device refused to do so. According to the XHCI protocol. it should return USB_ERR_STALLED. And this kind of error is definitely ignorable.

Sponsored by: The FreeBSD Foundation

Diff Detail

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

Event Timeline

kevans added inline comments.
lib/libusb/libusb10_io.c
505

This seems to have accidentally conflated error namespaces, which would have coincidentally worked since the values are the same here.

507

Not strictly necessary, but IMO nice to call it out as a reminder. I'd maybe pair it with an explanation at the final return down below of where you might expect err > 0 or an assertion if that just can't happen.

lib/libusb/libusb20_ugen20.c
799

style(9)

sys/dev/usb/usb_generic.c
895

Maybe paranoid, but I'd probably recommend:

MPASS(error < nitems(usb_error_to_errno);