usb: host: xhci: check DYING state earlier
PATCH 2/20 usb: host: xhci: check DYING state earlier
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 5 lines · Mathias Nyman
Quoted 3 lines · Felipe Balbi
Instead of allocating urb priv and, maybe, bail out due to xhci being in DYING state, we can move the check earlier and avoid the memory allocation altogether.
Quoted 6 lines
Quoted 4 lines
This also moves checking for DYING outside the lock.
Most cases set DYING with lock held, so if we first get the lock before checking DYING we have a better chance of not being in the process of dying.
pretty sure that's atomic, though.
That's not what I'm after, your fix is cleaning up code in the case where DYING flag is set before xhci_urb_enqueue() is called. I'm worried about the case when setting DYING flag races with xhci_urb_enqueue(). i.e. xhci_urb_enqueue() is spinning on the lock, waiting, while some other part of the driver is desperately trying to access hw with lock held, failing, finally setting DYING flag, and then releasing lock.
If the check is done before taking the lock then the URB might be queued on dying device, at a time when xhci_hc_died already started cancelling and giving back all queued URB
Quoted 8 lines
Quoted 2 lines
Small thing, but so is this cleanup, so not sure its worth the change
Look at the result. With this change we don't need to take a lock, allocate memory, search for endpoint index, search for endpoint state. All of those are needed for proper operation of the function, but if the controller has already died, there's no point in going any further.
But we might miss the fact that host died, and go even further, adding URB to list, writing TRBs to ringbuffers etc.
In code we save one line,
goto: free_priv
-Mathias
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html