]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: xhci: limit number of ports to 127
authorNiklas Neronin <niklas.neronin@linux.intel.com>
Wed, 19 Nov 2025 14:24:10 +0000 (16:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Nov 2025 13:53:00 +0000 (14:53 +0100)
The xHCI driver allocates various port-related structures based on the
maximum number of ports reported by the controller. The Number of Ports
(MaxPorts) field occupies bits 31:24 of the HCSPARAMS1 register and can
represent values up to 255. However, the 'HCS_MAX_PORTS()' macro currently
reads bits 30:24, effectively limiting the maximum to 127.

Fixing the macro increases the reported port limit to 255, which in turn
increases memory usage regardless of how many ports are actually used.

To maintain compatibility and control memory consumption, set
'xhci->max_ports' to the minimum of the value read from 'HCS_MAX_PORTS()'
and 127 (MAX_HC_PORTS). This preserves the existing limit while making
the restriction explicit and easier to adjust in the future.

Summary:
 * Port allocations are now limited to 127.
 * HC max ports macro now correctly reads the MaxPorts value.
 * Macro 'MAX_HC_PORTS' can be modified to set the port limit.

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://patch.msgid.link/20251119142417.2820519-17-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-caps.h
drivers/usb/host/xhci.c
drivers/usb/host/xhci.h

index 89bc83e4f1ebce2c53bd4daca939b20ac5ec2255..8390c969389e3ecd50ffedbcf5fececb77b8c67c 100644 (file)
@@ -12,8 +12,8 @@
 #define HCS_SLOTS_MASK         0xff
 /* bits 8:18, Max Interrupters */
 #define HCS_MAX_INTRS(p)       (((p) >> 8) & 0x7ff)
-/* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
-#define HCS_MAX_PORTS(p)       (((p) >> 24) & 0x7f)
+/* bits 31:24, Max Ports - max value is 255 */
+#define HCS_MAX_PORTS(p)       (((p) >> 24) & 0xff)
 
 /* HCSPARAMS2 - hcs_params2 - bitmasks */
 /* bits 0:3, frames or uframes that SW needs to queue transactions
index ad5ef294d4f3489a6dbd9077f5eac1fb0f525abf..cb82b15fc20347a6787cf8b9e057a1cfd8dc8525 100644 (file)
@@ -5448,7 +5448,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
                xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2);
 
        xhci->max_slots = HCS_MAX_SLOTS(hcs_params1);
-       xhci->max_ports = HCS_MAX_PORTS(hcs_params1);
+       xhci->max_ports = min(HCS_MAX_PORTS(hcs_params1), MAX_HC_PORTS);
        /* xhci-plat or xhci-pci might have set max_interrupters already */
        if ((!xhci->max_interrupters) || xhci->max_interrupters > HCS_MAX_INTRS(hcs_params1))
                xhci->max_interrupters = HCS_MAX_INTRS(hcs_params1);
index fface54dbc7ab311b1e1f233271af35cb189a338..e04bc491a22b9b0d97d5de834dc9c82dbb286a54 100644 (file)
 
 /* Max number of USB devices for any host controller - limit in section 6.1 */
 #define MAX_HC_SLOTS           256
-/* Section 5.3.3 - MaxPorts */
+/*
+ * Max Number of Ports. xHCI specification section 5.3.3
+ * Valid values are in the range of 1 to 255.
+ */
 #define MAX_HC_PORTS           127
 
 /*