[PATCH] iommu/amd: Fix IOMMU PCI device reference leak in iommu_init_pci()

Wentao Liang posted 1 patch 1 week, 1 day ago
drivers/iommu/amd/init.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] iommu/amd: Fix IOMMU PCI device reference leak in iommu_init_pci()
Posted by Wentao Liang 1 week, 1 day ago
iommu_init_pci() takes a reference on the IOMMU's PCI device with
pci_get_domain_bus_and_slot() and keeps it for the lifetime of the
IOMMU, but free_iommu_one() frees the IOMMU without ever dropping that
reference.  It is leaked whenever an IOMMU is torn down again on an
init error path.

Release the reference in free_iommu_one(), after the sysfs device that
uses it as parent has been removed.

Fixes: 3eaf28a1cd26 ("AMD IOMMU: save pci_dev instead of devid")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/iommu/amd/init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 3bdb380d23e9..4b155970151d 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -1810,6 +1810,7 @@ static void __init free_iommu_one(struct amd_iommu *iommu)
 	free_ga_log(iommu);
 	iommu_unmap_mmio_space(iommu);
 	amd_iommu_iopf_uninit(iommu);
+	pci_dev_put(iommu->dev);
 }
 
 static void __init free_iommu_all(void)
-- 
2.34.1