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

xhci: refactor xhci_urb_enqueue

Use switch instead of several if statements

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Nyman and committed by
Greg Kroah-Hartman
6969408d 7e64b037

+37 -56
+37 -56
drivers/usb/host/xhci.c
··· 1334 1334 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1335 1335 unsigned long flags; 1336 1336 int ret = 0; 1337 - unsigned int slot_id, ep_index; 1337 + unsigned int slot_id, ep_index, ep_state; 1338 1338 struct urb_priv *urb_priv; 1339 1339 int num_tds; 1340 1340 ··· 1348 1348 if (!HCD_HW_ACCESSIBLE(hcd)) { 1349 1349 if (!in_interrupt()) 1350 1350 xhci_dbg(xhci, "urb submitted during PCI suspend\n"); 1351 - ret = -ESHUTDOWN; 1352 - goto exit; 1351 + return -ESHUTDOWN; 1353 1352 } 1354 1353 1355 1354 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) ··· 1385 1386 return ret; 1386 1387 } 1387 1388 } 1389 + } 1388 1390 1389 - /* We have a spinlock and interrupts disabled, so we must pass 1390 - * atomic context to this function, which may allocate memory. 1391 - */ 1392 - spin_lock_irqsave(&xhci->lock, flags); 1393 - if (xhci->xhc_state & XHCI_STATE_DYING) 1394 - goto dying; 1391 + spin_lock_irqsave(&xhci->lock, flags); 1392 + 1393 + if (xhci->xhc_state & XHCI_STATE_DYING) { 1394 + xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", 1395 + urb->ep->desc.bEndpointAddress, urb); 1396 + ret = -ESHUTDOWN; 1397 + goto free_priv; 1398 + } 1399 + 1400 + switch (usb_endpoint_type(&urb->ep->desc)) { 1401 + 1402 + case USB_ENDPOINT_XFER_CONTROL: 1395 1403 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, 1396 - slot_id, ep_index); 1397 - if (ret) 1398 - goto free_priv; 1399 - spin_unlock_irqrestore(&xhci->lock, flags); 1400 - } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { 1401 - spin_lock_irqsave(&xhci->lock, flags); 1402 - if (xhci->xhc_state & XHCI_STATE_DYING) 1403 - goto dying; 1404 - if (xhci->devs[slot_id]->eps[ep_index].ep_state & 1405 - EP_GETTING_STREAMS) { 1406 - xhci_warn(xhci, "WARN: Can't enqueue URB while bulk ep " 1407 - "is transitioning to using streams.\n"); 1404 + slot_id, ep_index); 1405 + break; 1406 + case USB_ENDPOINT_XFER_BULK: 1407 + ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; 1408 + if (ep_state & (EP_GETTING_STREAMS | EP_GETTING_NO_STREAMS)) { 1409 + xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", 1410 + ep_state); 1408 1411 ret = -EINVAL; 1409 - } else if (xhci->devs[slot_id]->eps[ep_index].ep_state & 1410 - EP_GETTING_NO_STREAMS) { 1411 - xhci_warn(xhci, "WARN: Can't enqueue URB while bulk ep " 1412 - "is transitioning to " 1413 - "not having streams.\n"); 1414 - ret = -EINVAL; 1415 - } else { 1416 - ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 1417 - slot_id, ep_index); 1412 + break; 1418 1413 } 1419 - if (ret) 1420 - goto free_priv; 1421 - spin_unlock_irqrestore(&xhci->lock, flags); 1422 - } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { 1423 - spin_lock_irqsave(&xhci->lock, flags); 1424 - if (xhci->xhc_state & XHCI_STATE_DYING) 1425 - goto dying; 1414 + ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 1415 + slot_id, ep_index); 1416 + break; 1417 + 1418 + 1419 + case USB_ENDPOINT_XFER_INT: 1426 1420 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, 1427 1421 slot_id, ep_index); 1428 - if (ret) 1429 - goto free_priv; 1430 - spin_unlock_irqrestore(&xhci->lock, flags); 1431 - } else { 1432 - spin_lock_irqsave(&xhci->lock, flags); 1433 - if (xhci->xhc_state & XHCI_STATE_DYING) 1434 - goto dying; 1422 + break; 1423 + 1424 + case USB_ENDPOINT_XFER_ISOC: 1435 1425 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, 1436 1426 slot_id, ep_index); 1437 - if (ret) 1438 - goto free_priv; 1439 - spin_unlock_irqrestore(&xhci->lock, flags); 1440 1427 } 1441 - exit: 1442 - return ret; 1443 - dying: 1444 - xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " 1445 - "non-responsive xHCI host.\n", 1446 - urb->ep->desc.bEndpointAddress, urb); 1447 - ret = -ESHUTDOWN; 1428 + 1429 + if (ret) { 1448 1430 free_priv: 1449 - xhci_urb_free_priv(urb_priv); 1450 - urb->hcpriv = NULL; 1431 + xhci_urb_free_priv(urb_priv); 1432 + urb->hcpriv = NULL; 1433 + } 1451 1434 spin_unlock_irqrestore(&xhci->lock, flags); 1452 1435 return ret; 1453 1436 }