]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iommu/amd: Fix pci_segment memleak in alloc_pci_segment()
authorJinhui Guo <guojinhui.liam@bytedance.com>
Mon, 27 Oct 2025 16:50:17 +0000 (00:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Jan 2026 09:14:39 +0000 (10:14 +0100)
commit 75ba146c2674ba49ed8a222c67f9abfb4a4f2a4f upstream.

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@vger.kernel.org
Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iommu/amd/init.c

index af147d279a294d15135e34252a5f997d9b884f1b..8659cb0bc7e6d31eef595bea69a502be23fcf59e 100644 (file)
@@ -1602,13 +1602,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,