Re: [PATCH] usb: xhci: fix refcount leak in xhci_port_bw_show()

From: Johan Hovold

Date: Fri Jun 12 2026 - 05:19:22 EST


On Thu, Jun 11, 2026 at 09:21:20PM +0800, WenTao Liang wrote:
> If xhci_port_bw_show() calls pm_runtime_get_sync() and it fails with
> a negative return value, the function returns the error directly without
> calling pm_runtime_put_sync(). This leaks the runtime PM usage count,
> preventing the device from ever suspending again.

A failure to resume to the device will generally prevent the device from
ever resuming again in itself.

> pm_runtime_get_sync() unconditionally increments dev->power.usage_count
> before calling rpm_resume(). If rpm_resume() fails, the usage count is
> not decremented — a well-known API pitfall. Add a pm_runtime_put_sync()

You are using pm_runtime_put_noidle() (as you should), not _sync().

> call on the error path to balance the reference.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: 59d50e53e070 ("usb: xhci: Add debugfs support for xHCI port bandwidth")
> Signed-off-by: WenTao Liang <vulab@xxxxxxxxxxx>

Again, how was this issue found?

Also, "refcount" in the summary is a bit misleading as it makes it
sounds like you're fixing a memory leak. Please use something like
"runtime pm (reference) leak" instead.

Johan