[PATCH] x86/PCI: Fix device reference leak in pirq_find_router()

Wentao Liang posted 1 patch 1 week, 3 days ago
arch/x86/pci/irq.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] x86/PCI: Fix device reference leak in pirq_find_router()
Posted by Wentao Liang 1 week, 3 days ago
pci_get_domain_bus_and_slot() takes a reference on the router device
looked up from the routing table. If the device is found but no router
handler probes it successfully, the reference is neither stored in
pirq_router_dev nor dropped. Put the device reference when the router
probe fails.

Fixes: ac7cd5e16df8 ("x86/PCI: Handle PIRQ routing tables with no router device given")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 arch/x86/pci/irq.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
index 0de436316a1d..2bb80b6bf606 100644
--- a/arch/x86/pci/irq.c
+++ b/arch/x86/pci/irq.c
@@ -1312,8 +1312,12 @@ static void __init pirq_find_router(struct irq_router *r)
 	if (rt->rtr_vendor) {
 		dev = pci_get_domain_bus_and_slot(0, rt->rtr_bus,
 						  rt->rtr_devfn);
-		if (dev && pirq_try_router(r, rt, dev))
-			pirq_router_dev = dev;
+		if (dev) {
+			if (pirq_try_router(r, rt, dev))
+				pirq_router_dev = dev;
+			else
+				pci_dev_put(dev);
+		}
 	} else {
 		dev = NULL;
 		for_each_pci_dev(dev) {
-- 
2.34.1