[PATCH] pci: fix memory leak when virtio pci hotplug

From: Zhiqiang Liu
Date: Sun Mar 21 2021 - 11:31:12 EST


From: Feilong Lin <linfeilong@xxxxxxxxxx>

Repeated hot-plugging of pci devices for a virtual
machine driven by virtio, we found that there is a
leak in kmalloc-4k, which was confirmed as the memory
of the pci_device structure. Then we found out that
it was missing pci_dev_put() after pci_get_slot() in
enable_slot() of acpiphp_glue.c.

Signed-off-by: Feilong Lin <linfeilong@xxxxxxxxxx>
Reviewed-by: Zhiqiang Liu <liuzhiqiang26@xxxxxxxxxx>
---
drivers/pci/hotplug/acpiphp_glue.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 3365c93abf0e..f031302ad401 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
slot->flags &= ~SLOT_ENABLED;
continue;
}
+ pci_dev_put(dev);
}
}

--
2.19.1