Page MenuHomeFreeBSD

usb: preserve error when doing request
AcceptedPublic

Authored by aokblast on Aug 29 2025, 5:25 PM.
Tags
None
Referenced Files
F161325655: D52244.id161288.diff
Thu, Jul 2, 8:22 PM
Unknown Object (File)
Wed, Jul 1, 11:21 PM
Unknown Object (File)
Sat, Jun 27, 3:33 AM
Unknown Object (File)
Fri, Jun 26, 11:09 AM
Unknown Object (File)
Sat, Jun 20, 9:58 AM
Unknown Object (File)
May 30 2026, 2:13 PM
Unknown Object (File)
May 17 2026, 11:26 AM
Unknown Object (File)
May 17 2026, 9:28 AM

Details

Reviewers
adrian
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 73823
Build 70706: arc lint + arc unit

Event Timeline

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

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
896

Maybe paranoid, but I'd probably recommend:

MPASS(error < nitems(usb_error_to_errno);
adrian added inline comments.
lib/libusb/libusb10_io.c
501

are these supposed to be LIBUSB20_ERROR_* errors?

This revision is now accepted and ready to land.Fri, Jun 19, 5:09 AM