[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250928053657.1205-1-guojinhui.liam@bytedance.com>
Date: Sun, 28 Sep 2025 13:36:57 +0800
From: Jinhui Guo <guojinhui.liam@...edance.com>
To: joro@...tes.org,
suravee.suthikulpanit@....com
Cc: guojinhui.liam@...edance.com,
iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org,
stable@...r.kernel.org
Subject: [PATCH] iommu/amd: Fix pci_segment memleak in alloc_pci_segment()
Fix a memory leak of struct amd_iommu_pci_segment in alloc_pci_segment()
when system memory (or contiguous memory) is insufficient.
Fixes: 04230c119930 ("iommu/amd: Introduce per PCI segment device table")
Fixes: eda797a27795 ("iommu/amd: Introduce per PCI segment rlookup table")
Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table")
Cc: stable@...r.kernel.org
Signed-off-by: Jinhui Guo <guojinhui.liam@...edance.com>
---
drivers/iommu/amd/init.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index ba9e582a8bbe..77afd5884984 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -1608,13 +1608,22 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list);
if (alloc_dev_table(pci_seg))
- return NULL;
+ goto err_free_pci_seg;
if (alloc_alias_table(pci_seg))
- return NULL;
+ goto err_free_dev_table;
if (alloc_rlookup_table(pci_seg))
- return NULL;
+ goto err_free_alias_table;
return pci_seg;
+
+err_free_alias_table:
+ free_alias_table(pci_seg);
+err_free_dev_table:
+ free_dev_table(pci_seg);
+err_free_pci_seg:
+ list_del(&pci_seg->list);
+ kfree(pci_seg);
+ return NULL;
}
static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id,
--
2.20.1
Powered by blists - more mailing lists