Skip to contentSkip to conversation

iommu/amd: Fix possible memory leak of 'domain'

PATCH Superseded Su Hui 3 participants 4 messages Jun 6, 2023 – Jun 7, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Su Hui

author
#0 lore raw

PATCH 1/1 iommu/amd: Fix possible memory leak of 'domain'

free memory of domain before return NULL.

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 · 1 line
2.30.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Su Hui

free memory of domain before return NULL.

Fixes 29f54745f245 ("iommu/amd: Add missing domain type checks")

-Vasant

Quoted 17 lines
---
 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) {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Su Hui
Quoted 13 lines · Su Hui

free memory of domain before return NULL.

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 +0 -0
index dc1ec6849775..f08e65629c74 100644

drivers/iommu/amd/iommu.c static struct protection_domain *protection_domain_alloc(unsigned int type) · line 2098

Quoted 6 lines
drivers/iommu/amd/iommu.c +1 -1
@@ -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;
 	}

It might be nicer to order to allocation after the type checks, it is more consistent with the other drivers

This is fine too

Thanks,
Jason

maintainer
#3 lore raw

Jason,

Quoted 24 lines · Jason Gunthorpe
Quoted 13 lines · Su Hui

free memory of domain before return NULL.

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 +0 -0
index dc1ec6849775..f08e65629c74 100644

drivers/iommu/amd/iommu.c static struct protection_domain *protection_domain_alloc(unsigned int type) · line 2098

Quoted 6 lines
drivers/iommu/amd/iommu.c +1 -1
@@ -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;
 	}

It might be nicer to order to allocation after the type checks, it is more consistent with the other drivers

Quoted 1 line

This is fine too

Right. We are working on cleaning up/re-arranging this code path. Hopefully I will have patches soon.

-Vasant