Page MenuHomeFreeBSD

libusb: implement libusb_get_max_alt_packet_size
AcceptedPublic

Authored by aokblast on Jul 9 2025, 10:51 AM.
Tags
None
Referenced Files
F160035461: D51225.diff
Sat, Jun 20, 7:04 PM
Unknown Object (File)
Mon, Jun 15, 6:30 PM
Unknown Object (File)
Mon, Jun 15, 4:03 AM
Unknown Object (File)
Sun, Jun 14, 4:31 AM
Unknown Object (File)
Mon, Jun 8, 4:46 PM
Unknown Object (File)
Fri, Jun 5, 2:01 AM
Unknown Object (File)
Thu, Jun 4, 3:36 PM
Unknown Object (File)
Thu, Jun 4, 11:40 AM

Details

Reviewers
bapt
kevans
adrian
Group Reviewers
USB
manpages
Summary

The libusb has a function to calculate the size from given interface,
alt_setting, endpoint. Implementing it by refactoring the calculating
function for libusb_get_max_iso_packet_size.

Sponsored By: FreeBSD Foundation

Diff Detail

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

Event Timeline

Add missing parentheses in return

Rebase to main and fix potential error

lwhsu added inline comments.
lib/libusb/libusb10.c
642

pdconf seems leaked here.

662

for all the early return below, except the if (ret < 0), pdconf needs being free()'d?

lib/libusb/libusb.3
206

do you mean multiply the multiplier?

unitrunker_unitrunker.net added inline comments.
lib/libusb/libusb.3
203

Returns the packet size on success,

Makefile
 82 MLINKS += libusb.3 libusb_get_max_packet_size.3
 83 MLINKS += libusb.3 libusb_get_max_iso_packet_size.3
  miss? MLINKS += libusb.3 libusb_get_max_alt_packet_size.3
 84 MLINKS += libusb.3 libusb_ref_device.3
lib/libusb/libusb10.c
564

Upstream return only

  • \returns the wMaxPacketSize value
  • \returns \ref LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
  • \returns \ref LIBUSB_ERROR_OTHER on other failure
579

Upstream return ep->wMaxPacketSize only when the device isn't a SuperSpeed device or retrieving the SS endpoint didn't worked.

So

  • USB3 ep + get companion descriptor failed will access wMaxPacketSize not return error.
  • USB3 BULKIN ep + (ss_ep->wBytesPerInterval = 0) + (ep->wMaxPacketSize = 1024) return 0 not 1024.
603

587 libusb speed api
603 libusb20 speed api
use the same one?

634

Upstream

  • \returns the maximum packet size which can be sent/received on this endpoint
  • \returns \ref LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
  • \returns \ref LIBUSB_ERROR_OTHER on other failure
680

endpoint is bEndpointAddress not index

681

Ditto.

705

Upstream returns

  • \returns the maximum packet size which can be sent/received on this endpoint
  • \returns \ref LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
  • \returns \ref LIBUSB_ERROR_OTHER on other failure
709

Ditto.

lib/libusb/libusb10.c
564

I think it is much better to have detailed error other than error from upstream implementation.

579

See above. And second one makes sense.

634

Same as above

680

You are right, thanks!

681

Same as above

705

Same as above

709

Same as above.

Use ERROR_OTHER instead of NO_DEVICE

  • Add MLINKS += libusb.3 libusb_get_max_alt_packet_size.3 in Makefile
  • Remove 680-683

Then LGTM

This revision is now accepted and ready to land.Thu, Jun 18, 5:10 AM