Skip to content

Commit 5b00369

Browse files
Su Huijoergroedel
authored andcommitted
iommu/amd: Fix possible memory leak of 'domain'
Move allocation code down to avoid memory leak. Fixes: 29f5474 ("iommu/amd: Add missing domain type checks") Signed-off-by: Su Hui <suhui@nfschina.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Link: https://lore.kernel.org/r/20230608021933.856045-1-suhui@nfschina.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 858fd16 commit 5b00369

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,10 +2078,6 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
20782078
int mode = DEFAULT_PGTABLE_LEVEL;
20792079
int ret;
20802080

2081-
domain = kzalloc(sizeof(*domain), GFP_KERNEL);
2082-
if (!domain)
2083-
return NULL;
2084-
20852081
/*
20862082
* Force IOMMU v1 page table when iommu=pt and
20872083
* when allocating domain for pass-through devices.
@@ -2097,6 +2093,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
20972093
return NULL;
20982094
}
20992095

2096+
domain = kzalloc(sizeof(*domain), GFP_KERNEL);
2097+
if (!domain)
2098+
return NULL;
2099+
21002100
switch (pgtable) {
21012101
case AMD_IOMMU_V1:
21022102
ret = protection_domain_init_v1(domain, mode);

0 commit comments

Comments
 (0)