Commit 75ba146c authored by Jinhui Guo's avatar Jinhui Guo Committed by Joerg Roedel
Browse files

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: 04230c11 ("iommu/amd: Introduce per PCI segment device table")
Fixes: eda797a2 ("iommu/amd: Introduce per PCI segment rlookup table")
Fixes: 99fc4ac3 ("iommu/amd: Introduce per PCI segment alias_table")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJinhui Guo <guojinhui.liam@bytedance.com>
Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
parent d1e281f8
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1710,13 +1710,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,