Page MenuHomeFreeBSD

libusb: implement libusb_get_max_alt_packet_size
ClosedPublic

Authored by aokblast on Jul 9 2025, 10:51 AM.
Tags
None
Referenced Files
F162464750: D51225.diff
Mon, Jul 13, 2:16 PM
Unknown Object (File)
Thu, Jul 9, 4:19 PM
Unknown Object (File)
Sat, Jul 4, 12:04 PM
Unknown Object (File)
Fri, Jul 3, 7:54 AM
Unknown Object (File)
Thu, Jul 2, 7:16 AM
Unknown Object (File)
Tue, Jun 30, 6:29 AM
Unknown Object (File)
Sun, Jun 28, 9:51 AM
Unknown Object (File)
Thu, Jun 25, 9:34 PM

Details

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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

Add missing parentheses in return

Rebase to main and fix potential error

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

pdconf seems leaked here.

670

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

lib/libusb/libusb.3
232

do you mean multiply the multiplier?

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

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
574

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
589

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.
613

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

642

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
696

endpoint is bEndpointAddress not index

696

Ditto.

720

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
724

Ditto.

lib/libusb/libusb10.c
574

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

589

See above. And second one makes sense.

642

Same as above

696

Same as above

696

You are right, thanks!

720

Same as above

724

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