Skip to contentSkip to conversation

usb: xhci: fix USB2 roothub port count clamp

PATCH New Zhang Cen 1 participant 1 message May 16

Subsystems (2)
lore
Share & tools
lore

Zhang Cen

author
#0 lore raw

PATCH 1/1 usb: xhci: fix USB2 roothub port count clamp

xhci_create_rhub_port_array() is passed the roothub whose port array is being built and the limit that matches that roothub's descriptor size. The limit check currently stores the clamped value in xhci->usb3_rhub.num_ports unconditionally.

When this helper handles the USB2 roothub, a controller advertising more than USB_MAXCHILDREN USB2 ports leaves xhci->usb2_rhub.num_ports unchanged. Later USB2 hub descriptor and status helpers use that count to size fixed USB2 descriptor and status bitmaps.

Clamp the roothub passed to the helper so both USB2 and USB3 counts are bounded before those paths use them.

Fixes 9a7ad750a8fb ("usb: xhci: move roothub port limit validation")

---

drivers/usb/host/xhci-mem.c +1 -1
index 997fe90f54e5..2545f96fd1ee 100644
@@ -2182,7 +2182,7 @@ static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, struct xhci_hub *
 	 * descriptors aren't longer than the USB core will allocate.
 	 */
 	if (rhub->num_ports > max_ports) {
-		xhci->usb3_rhub.num_ports = max_ports;
+		rhub->num_ports = max_ports;
 		xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Limiting USB%u root hub ports to %u",
 			       rhub->maj_rev, max_ports);
 	}