Skip to content

Commit 3505478

Browse files
XNUBIAgregkh
authored andcommitted
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: c311e39 ("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>
1 parent da0345d commit 3505478

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

drivers/usb/host/xhci-hub.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,25 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
394394
GFP_NOWAIT);
395395
if (!command) {
396396
spin_unlock_irqrestore(&xhci->lock, flags);
397-
xhci_free_command(xhci, cmd);
398-
return -ENOMEM;
397+
ret = -ENOMEM;
398+
goto cmd_cleanup;
399+
}
399400

401+
ret = xhci_queue_stop_endpoint(xhci, command, slot_id,
402+
i, suspend);
403+
if (ret) {
404+
spin_unlock_irqrestore(&xhci->lock, flags);
405+
xhci_free_command(xhci, command);
406+
goto cmd_cleanup;
400407
}
401-
xhci_queue_stop_endpoint(xhci, command, slot_id, i,
402-
suspend);
403408
}
404409
}
405-
xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend);
410+
ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend);
411+
if (ret) {
412+
spin_unlock_irqrestore(&xhci->lock, flags);
413+
goto cmd_cleanup;
414+
}
415+
406416
xhci_ring_cmd_db(xhci);
407417
spin_unlock_irqrestore(&xhci->lock, flags);
408418

@@ -413,6 +423,8 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
413423
xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n");
414424
ret = -ETIME;
415425
}
426+
427+
cmd_cleanup:
416428
xhci_free_command(xhci, cmd);
417429
return ret;
418430
}

0 commit comments

Comments
 (0)