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: clean up handling of upper bits in SetPortFeature wIndex

In Set Port Feature requests, the upper byte of 'wIndex' encodes
feature-specific parameters. The current code reads these upper bits in
an early pre-processing block, and then the same feature is handled again
later in the main switch statement. This results in duplicated condition
checks and makes the control flow harder to follow.

Move all feature-specific extraction of 'wIndex' upper bits into the
main SetPortFeature logic so that each feature is handled in exactly one
place. This reduces duplication, makes the handling clearer, and keeps
'wIndex' parsing local to the code that actually uses the values.

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

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
b7a56f86 ec5521a7

+12 -13
+12 -13
drivers/usb/host/xhci-hub.c
··· 1205 1205 u32 temp, status; 1206 1206 int retval = 0; 1207 1207 struct xhci_bus_state *bus_state; 1208 - u16 link_state = 0; 1209 - u16 wake_mask = 0; 1210 - u16 timeout = 0; 1211 - u16 test_mode = 0; 1208 + u16 link_state; 1209 + u16 wake_mask; 1210 + u8 timeout; 1211 + u8 test_mode; 1212 1212 struct xhci_hub *rhub; 1213 1213 struct xhci_port **ports; 1214 1214 struct xhci_port *port; ··· 1286 1286 } 1287 1287 break; 1288 1288 case SetPortFeature: 1289 - if (wValue == USB_PORT_FEAT_LINK_STATE) 1290 - link_state = (wIndex & 0xff00) >> 3; 1291 - if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK) 1292 - wake_mask = wIndex & 0xff00; 1293 - if (wValue == USB_PORT_FEAT_TEST) 1294 - test_mode = (wIndex & 0xff00) >> 8; 1295 - /* The MSB of wIndex is the U1/U2 timeout */ 1296 - timeout = (wIndex & 0xff00) >> 8; 1297 - 1298 1289 portnum = (wIndex & 0xff) - 1; 1299 1290 if (!in_range(portnum, 0, max_ports)) 1300 1291 goto error; ··· 1340 1349 bus_state->suspended_ports |= 1 << portnum; 1341 1350 break; 1342 1351 case USB_PORT_FEAT_LINK_STATE: 1352 + link_state = (wIndex & 0xff00) >> 3; 1343 1353 temp = xhci_portsc_readl(port); 1344 1354 /* Disable port */ 1345 1355 if (link_state == USB_SS_PORT_LS_SS_DISABLED) { ··· 1490 1498 hcd->self.busnum, portnum + 1, temp); 1491 1499 break; 1492 1500 case USB_PORT_FEAT_REMOTE_WAKE_MASK: 1501 + wake_mask = wIndex & 0xff00; 1493 1502 xhci_set_remote_wake_mask(xhci, port, wake_mask); 1494 1503 temp = xhci_portsc_readl(port); 1495 1504 xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n", ··· 1504 1511 case USB_PORT_FEAT_U1_TIMEOUT: 1505 1512 if (hcd->speed < HCD_USB3) 1506 1513 goto error; 1514 + 1515 + timeout = (wIndex & 0xff00) >> 8; 1507 1516 temp = readl(&port->port_reg->portpmsc); 1508 1517 temp &= ~PORT_U1_TIMEOUT_MASK; 1509 1518 temp |= PORT_U1_TIMEOUT(timeout); ··· 1514 1519 case USB_PORT_FEAT_U2_TIMEOUT: 1515 1520 if (hcd->speed < HCD_USB3) 1516 1521 goto error; 1522 + 1523 + timeout = (wIndex & 0xff00) >> 8; 1517 1524 temp = readl(&port->port_reg->portpmsc); 1518 1525 temp &= ~PORT_U2_TIMEOUT_MASK; 1519 1526 temp |= PORT_U2_TIMEOUT(timeout); ··· 1525 1528 /* 4.19.6 Port Test Modes (USB2 Test Mode) */ 1526 1529 if (hcd->speed != HCD_USB2) 1527 1530 goto error; 1531 + 1532 + test_mode = (wIndex & 0xff00) >> 8; 1528 1533 if (test_mode > USB_TEST_FORCE_ENABLE || 1529 1534 test_mode < USB_TEST_J) 1530 1535 goto error;