Re: [PATCH v3] usb: core: hub: Re-guess ep0 maxpacket size after reset

From: Michal Pecio

Date: Mon Nov 09 2026 - 15:34:52 EST


On Mon, 9 Nov 2026 11:05:30 -0500, Alan Stern wrote:
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> > index 199d3f535a89..d86bbba1457c 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -4969,31 +4969,29 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
> > }
> > oldspeed = udev->speed;
> >
> > - if (initial) {
> > - /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ...
> > - * it's fixed size except for full speed devices.
> > + /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ...
> > + * it's fixed size except for full speed devices.
> > + */
> > + switch (udev->speed) {
> > + case USB_SPEED_SUPER_PLUS:
> > + case USB_SPEED_SUPER:
> > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
> > + break;
> > + case USB_SPEED_HIGH: /* fixed at 64 */
> > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
> > + break;
> > + case USB_SPEED_FULL: /* 8, 16, 32, or 64 */
> > + /* to determine the ep0 maxpacket size, try to read
> > + * the device descriptor to get bMaxPacketSize0 and
> > + * then correct our initial guess.
> > */
> > - switch (udev->speed) {
> > - case USB_SPEED_SUPER_PLUS:
> > - case USB_SPEED_SUPER:
> > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
> > - break;
> > - case USB_SPEED_HIGH: /* fixed at 64 */
> > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
> > - break;
> > - case USB_SPEED_FULL: /* 8, 16, 32, or 64 */
> > - /* to determine the ep0 maxpacket size, try to read
> > - * the device descriptor to get bMaxPacketSize0 and
> > - * then correct our initial guess.
> > - */
> > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
> > - break;
> > - case USB_SPEED_LOW: /* fixed at 8 */
> > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8);
> > - break;
> > - default:
> > - goto fail;
> > - }
> > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
> > + break;
> > + case USB_SPEED_LOW: /* fixed at 8 */
> > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8);
> > + break;
> > + default:
> > + goto fail;
> > }
>
> The usb_ep0_reinit() call belongs here, right after
> udev->ep0.desc.wMaxPacketSize is set.
>
> >
> > speed = usb_speed_string(udev->speed);
> > @@ -5062,6 +5060,9 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
> > goto fail;
> > }
> >
> > + /* Sync the guessed ep0 maxpacket size to hardware if needed */
> > + usb_ep0_reinit(udev);
>
> Not here. And not inside the retry loop -- ep0_reinit should be
> called only once since the maxpacket value is changed only once.

Sashiko pointed out that xhci-hcd may not perform ep0_reinit() properly
until address_device() or enable_device() is called.

So it's either this kludge, or dependency on an xhci-hcd patch which
didn't exist until today:

https://lore.kernel.org/linux-usb/20261109112846.04bfeb0f.michal.pecio@xxxxxxxxx/

Regards,
Michal