diff mbox series

[v3] xhci: fix runtime PM imbalance in USB2 resume

Message ID 20220302065106.85021-1-henryl@nvidia.com
State New
Headers show
Series [v3] xhci: fix runtime PM imbalance in USB2 resume | expand

Commit Message

Henry Lin March 2, 2022, 6:51 a.m. UTC
A race between system resume and device-initiated resume may result in
runtime PM imbalance on USB2 root hub. If a device-initiated resume
starts and system resume xhci_bus_resume() directs U0 before hub driver
sees the resuming device in RESUME state, device-initiated resume will
not be finished in xhci_handle_usb2_port_link_resume(). In this case,
usb_hcd_end_port_resume() call is missing.

This changes calls usb_hcd_end_port_resume() if resuming device reaches
U0 to keep runtime PM balance.

Fixes: a231ec41e6f6 ("xhci: refactor U0 link state handling in get_port_status")
Signed-off-by: Henry Lin <henryl@nvidia.com>
---

Changes in v2:
- Add Fixes tag in change log

Changes in v3:
- Revise changelog
- Only call usb_hcd_end_port_resume() if xhci_irq() detected the device-initiated resume

[v2] https://lore.kernel.org/all/20220225071506.22012-1-henryl@nvidia.com/
[v1] https://lore.kernel.org/all/20220225055311.92447-1-henryl@nvidia.com/
 
 drivers/usb/host/xhci-hub.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index df3522dab31b..5e7a4dfc59d2 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1088,6 +1088,9 @@  static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
 		if (link_state == XDEV_U2)
 			*status |= USB_PORT_STAT_L1;
 		if (link_state == XDEV_U0) {
+			if (bus_state->resume_done[portnum])
+				usb_hcd_end_port_resume(&port->rhub->hcd->self,
+							portnum);
 			bus_state->resume_done[portnum] = 0;
 			clear_bit(portnum, &bus_state->resuming_ports);
 			if (bus_state->suspended_ports & (1 << portnum)) {