Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: xhci: move roothub port limit validation

Function xhci_setup_port_arrays() limits the number of roothub ports
for both USB 2 and 3, this causes code repetition.

Solve this by moving roothub port limits validation to
xhci_create_rhub_port_array().

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/20260402131342.2628648-24-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
9a7ad750 d81a5580

+18 -27
+18 -27
drivers/usb/host/xhci-mem.c
··· 2165 2165 /* FIXME: Should we disable ports not in the Extended Capabilities? */ 2166 2166 } 2167 2167 2168 - static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, 2169 - struct xhci_hub *rhub, gfp_t flags) 2168 + static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, struct xhci_hub *rhub, 2169 + unsigned int max_ports, gfp_t flags) 2170 2170 { 2171 2171 int port_index = 0; 2172 2172 int i; 2173 2173 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; 2174 2174 2175 - if (!rhub->num_ports) 2175 + if (!rhub->num_ports) { 2176 + xhci_info(xhci, "USB%u root hub has no ports\n", rhub->maj_rev); 2176 2177 return; 2178 + } 2179 + 2180 + /* 2181 + * Place limits on the number of roothub ports so that the hub 2182 + * descriptors aren't longer than the USB core will allocate. 2183 + */ 2184 + if (rhub->num_ports > max_ports) { 2185 + xhci->usb3_rhub.num_ports = max_ports; 2186 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Limiting USB%u root hub ports to %u", 2187 + rhub->maj_rev, max_ports); 2188 + } 2189 + 2177 2190 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), 2178 2191 flags, dev_to_node(dev)); 2179 2192 if (!rhub->ports) ··· 2282 2269 "Found %u USB 2.0 ports and %u USB 3.0 ports.", 2283 2270 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); 2284 2271 2285 - /* Place limits on the number of roothub ports so that the hub 2286 - * descriptors aren't longer than the USB core will allocate. 2287 - */ 2288 - if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { 2289 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2290 - "Limiting USB 3.0 roothub ports to %u.", 2291 - USB_SS_MAXPORTS); 2292 - xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; 2293 - } 2294 - if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { 2295 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2296 - "Limiting USB 2.0 roothub ports to %u.", 2297 - USB_MAXCHILDREN); 2298 - xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; 2299 - } 2300 - 2301 - if (!xhci->usb2_rhub.num_ports) 2302 - xhci_info(xhci, "USB2 root hub has no ports\n"); 2303 - 2304 - if (!xhci->usb3_rhub.num_ports) 2305 - xhci_info(xhci, "USB3 root hub has no ports\n"); 2306 - 2307 - xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); 2308 - xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); 2272 + xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, USB_MAXCHILDREN, flags); 2273 + xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, USB_SS_MAXPORTS, flags); 2309 2274 2310 2275 return 0; 2311 2276 }