usb: xhci: Handle error condition in xhci_stop_device()
authorMayank Rana <mrana@codeaurora.org>
Fri, 6 Oct 2017 14:45:30 +0000 (17:45 +0300)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 1 Jan 2018 20:51:55 +0000 (20:51 +0000)
commit22b6b54299895a5eba08ed789f9f1a251d7e2129
tree37d8b4b584c40061d211fab6ae4b0139e746dd75
parentbcb358260e25e6125623d934623db6fdb6a6b31c
usb: xhci: Handle error condition in xhci_stop_device()

commit b3207c65dfafae27e7c492cb9188c0dc0eeaf3fd upstream.

xhci_stop_device() calls xhci_queue_stop_endpoint() multiple times
without checking the return value. xhci_queue_stop_endpoint() can
return error if the HC is already halted or unable to queue commands.
This can cause a deadlock condition as xhci_stop_device() would
end up waiting indefinitely for a completion for the command that
didn't get queued. Fix this by checking the return value and bailing
out of xhci_stop_device() in case of error. This patch happens to fix
potential memory leaks of the allocated command structures as well.

Fixes: c311e391a7ef ("xhci: rework command timeout and cancellation,")
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/usb/host/xhci-hub.c