]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[xhci] Use root hub port number to determine slot type
authorMichael Brown <mcb30@ipxe.org>
Fri, 18 Jul 2025 13:24:23 +0000 (14:24 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 18 Jul 2025 13:58:56 +0000 (14:58 +0100)
We currently use the downstream hub's port number to determine the
xHCI slot type for a newly connected USB device.  The downstream hub
port number is irrelevant to the xHCI controller's supported protocols
table: the relevant value is the number of the root hub port through
which the device is attached.

Fix by using the root hub port number instead of the immediate parent
hub's port number.

This bug has not previously been detected since the slot type for the
first N root hub ports will invariably be zero to indicate that these
are USB ports.  For any xHCI controller with a sufficiently large
number of root hub ports, the code would therefore end up happening to
calculate the correct slot type value despite using an incorrect port
number.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/usb/xhci.c

index 30ee09bbb1f46c75dc37490ccb8bb27a5ea5d3e1..b7781f3edd9589de501dae517b350401340ccb78 100644 (file)
@@ -2770,6 +2770,7 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
  */
 static int xhci_device_open ( struct usb_device *usb ) {
        struct xhci_device *xhci = usb_bus_get_hostdata ( usb->port->hub->bus );
+       struct usb_port *root_port = usb_root_hub_port ( usb );
        struct usb_port *tt = usb_transaction_translator ( usb );
        struct xhci_slot *slot;
        struct xhci_slot *tt_slot;
@@ -2779,7 +2780,7 @@ static int xhci_device_open ( struct usb_device *usb ) {
        int rc;
 
        /* Determine applicable slot type */
-       type = xhci_port_slot_type ( xhci, usb->port->address );
+       type = xhci_port_slot_type ( xhci, root_port->address );
        if ( type < 0 ) {
                rc = type;
                DBGC ( xhci, "XHCI %s-%d has no slot type\n",