mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: host: Fix companion leak in usb_enable_intel_xhci_ports()
@ 2026-09-16 16:48 Wentao Liang
  2026-09-30 13:27 ` Mathias Nyman
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-16 16:48 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, linux-usb, mathias.nyman, sarah.a.sharp,
	Wentao Liang, stable

usb_enable_intel_xhci_ports() iterates over the PCI devices with
for_each_pci_dev() to check whether an Intel EHCI companion exists and
breaks out of the loop as soon as one is found. for_each_pci_dev()
takes a reference on the device returned by pci_get_device(), and
breaking out of the loop leaves that reference held. The companion
pointer is only used to set the ehci_found flag and the reference is
never dropped, leaking a reference to the EHCI companion device on
every port switch operation.

Drop the reference with pci_dev_put() once the lookup is done. When no
companion is found the loop leaves companion set to NULL, for which
pci_dev_put() is a no-op.

Fixes: 26b76798e050 ("Intel xhci: refactor EHCI/xHCI port switching")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/usb/host/pci-quirks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 0404489c2f6a..bde5bc248d45 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -1076,6 +1076,8 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
 			break;
 		}
 	}
+	/* for_each_pci_dev() takes a reference on the found companion */
+	pci_dev_put(companion);
 
 	if (!ehci_found)
 		return;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-30 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 16:48 [PATCH] usb: host: Fix companion leak in usb_enable_intel_xhci_ports() Wentao Liang
2026-09-30 13:27 ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®