Skip to content

Commit 75ba146

Browse files
guojinhui-liamjoergroedel
authored andcommitted
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: 04230c1 ("iommu/amd: Introduce per PCI segment device table") Fixes: eda797a ("iommu/amd: Introduce per PCI segment rlookup table") Fixes: 99fc4ac ("iommu/amd: Introduce per PCI segment alias_table") Cc: stable@vger.kernel.org Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent d1e281f commit 75ba146

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/iommu/amd/init.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,13 +1710,22 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
17101710
list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list);
17111711

17121712
if (alloc_dev_table(pci_seg))
1713-
return NULL;
1713+
goto err_free_pci_seg;
17141714
if (alloc_alias_table(pci_seg))
1715-
return NULL;
1715+
goto err_free_dev_table;
17161716
if (alloc_rlookup_table(pci_seg))
1717-
return NULL;
1717+
goto err_free_alias_table;
17181718

17191719
return pci_seg;
1720+
1721+
err_free_alias_table:
1722+
free_alias_table(pci_seg);
1723+
err_free_dev_table:
1724+
free_dev_table(pci_seg);
1725+
err_free_pci_seg:
1726+
list_del(&pci_seg->list);
1727+
kfree(pci_seg);
1728+
return NULL;
17201729
}
17211730

17221731
static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id,

0 commit comments

Comments
 (0)