Skip to contentSkip to conversation

iommu/amd: Fix memory leak when domain type checks fail

PATCH In review Hao Ge 2 participants 2 messages Jun 12, 2023 – Jun 14, 2023

Subsystems (2)
lore
Share & tools
lore

Hao Ge

author
#0 lore raw

PATCH 1/1 iommu/amd: Fix memory leak when domain type checks fail

When domain type checks fail,we also should free protection_domain struct to avoid memory leak in protection_domain_alloc

Fixes 29f54745f245 ("iommu/amd: Add missing domain type checks")
---
 drivers/iommu/amd/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +1 -1
index dc1ec6849775..f08e65629c74 100644
@@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	} else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) {
 		pgtable = amd_iommu_pgtable;
 	} else {
-		return NULL;
+		goto out_err;
 	}
 
 	switch (pgtable) {
Signature · 5 lines
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus
maintainer
#1 lore raw

Hi,

Quoted 3 lines · Hao Ge

When domain type checks fail,we also should free protection_domain struct to avoid memory leak in protection_domain_alloc

There is another patch from Su to fix this issue [1].

[1] https://lore.kernel.org/linux-iommu/[email protected]/

-Vasant

Quoted 19 lines
Fixes 29f54745f245 ("iommu/amd: Add missing domain type checks")
---
 drivers/iommu/amd/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +1 -1
index dc1ec6849775..f08e65629c74 100644
@@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	} else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) {
 		pgtable = amd_iommu_pgtable;
 	} else {
-		return NULL;
+		goto out_err;
 	}
 
 	switch (pgtable) {