iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iommu/amd: Fix possible memory leak of 'domain'
@ 2023-06-08  2:19 Su Hui
  2023-06-08  4:17 ` Vasant Hegde
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Su Hui @ 2023-06-08  2:19 UTC (permalink / raw)
  To: Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy
  Cc: kevin.tian, vasant.hegde, jgg, iommu, linux-kernel, Su Hui

Move allocation code down to avoid memory leak.

Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
Changes in v2:
	change code order is better and more consistent with other
drivers. 
 drivers/iommu/amd/iommu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index dc1ec6849775..e8a2e5984acb 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2078,10 +2078,6 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	int mode = DEFAULT_PGTABLE_LEVEL;
 	int ret;
 
-	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
-	if (!domain)
-		return NULL;
-
 	/*
 	 * Force IOMMU v1 page table when iommu=pt and
 	 * when allocating domain for pass-through devices.
@@ -2097,6 +2093,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 		return NULL;
 	}
 
+	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
+	if (!domain)
+		return NULL;
+
 	switch (pgtable) {
 	case AMD_IOMMU_V1:
 		ret = protection_domain_init_v1(domain, mode);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iommu/amd: Fix possible memory leak of 'domain'
  2023-06-08  2:19 [PATCH v2] iommu/amd: Fix possible memory leak of 'domain' Su Hui
@ 2023-06-08  4:17 ` Vasant Hegde
  2023-06-12 18:12 ` Jerry Snitselaar
  2023-06-12 18:17 ` Jason Gunthorpe
  2 siblings, 0 replies; 4+ messages in thread
From: Vasant Hegde @ 2023-06-08  4:17 UTC (permalink / raw)
  To: Su Hui, Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy
  Cc: kevin.tian, jgg, iommu, linux-kernel

On 6/8/2023 7:49 AM, Su Hui wrote:
> Move allocation code down to avoid memory leak.
> 
> Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks")
> Signed-off-by: Su Hui <suhui@nfschina.com>

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>


-Vasant


> ---
> Changes in v2:
> 	change code order is better and more consistent with other
> drivers. 
>  drivers/iommu/amd/iommu.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index dc1ec6849775..e8a2e5984acb 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2078,10 +2078,6 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
>  	int mode = DEFAULT_PGTABLE_LEVEL;
>  	int ret;
>  
> -	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> -	if (!domain)
> -		return NULL;
> -
>  	/*
>  	 * Force IOMMU v1 page table when iommu=pt and
>  	 * when allocating domain for pass-through devices.
> @@ -2097,6 +2093,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
>  		return NULL;
>  	}
>  
> +	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> +	if (!domain)
> +		return NULL;
> +
>  	switch (pgtable) {
>  	case AMD_IOMMU_V1:
>  		ret = protection_domain_init_v1(domain, mode);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iommu/amd: Fix possible memory leak of 'domain'
  2023-06-08  2:19 [PATCH v2] iommu/amd: Fix possible memory leak of 'domain' Su Hui
  2023-06-08  4:17 ` Vasant Hegde
@ 2023-06-12 18:12 ` Jerry Snitselaar
  2023-06-12 18:17 ` Jason Gunthorpe
  2 siblings, 0 replies; 4+ messages in thread
From: Jerry Snitselaar @ 2023-06-12 18:12 UTC (permalink / raw)
  To: Su Hui
  Cc: Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy,
	kevin.tian, vasant.hegde, jgg, iommu, linux-kernel

On Thu, Jun 08, 2023 at 10:19:34AM +0800, Su Hui wrote:
> Move allocation code down to avoid memory leak.
> 
> Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks")
> Signed-off-by: Su Hui <suhui@nfschina.com>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>

> ---
> Changes in v2:
> 	change code order is better and more consistent with other
> drivers. 
>  drivers/iommu/amd/iommu.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index dc1ec6849775..e8a2e5984acb 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2078,10 +2078,6 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
>  	int mode = DEFAULT_PGTABLE_LEVEL;
>  	int ret;
>  
> -	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> -	if (!domain)
> -		return NULL;
> -
>  	/*
>  	 * Force IOMMU v1 page table when iommu=pt and
>  	 * when allocating domain for pass-through devices.
> @@ -2097,6 +2093,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
>  		return NULL;
>  	}
>  
> +	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> +	if (!domain)
> +		return NULL;
> +
>  	switch (pgtable) {
>  	case AMD_IOMMU_V1:
>  		ret = protection_domain_init_v1(domain, mode);
> -- 
> 2.30.2
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iommu/amd: Fix possible memory leak of 'domain'
  2023-06-08  2:19 [PATCH v2] iommu/amd: Fix possible memory leak of 'domain' Su Hui
  2023-06-08  4:17 ` Vasant Hegde
  2023-06-12 18:12 ` Jerry Snitselaar
@ 2023-06-12 18:17 ` Jason Gunthorpe
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2023-06-12 18:17 UTC (permalink / raw)
  To: Su Hui
  Cc: Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy,
	kevin.tian, vasant.hegde, iommu, linux-kernel

On Thu, Jun 08, 2023 at 10:19:34AM +0800, Su Hui wrote:
> Move allocation code down to avoid memory leak.
> 
> Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
> Changes in v2:
> 	change code order is better and more consistent with other
> drivers. 
>  drivers/iommu/amd/iommu.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Thanks,
Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-12 18:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08  2:19 [PATCH v2] iommu/amd: Fix possible memory leak of 'domain' Su Hui
2023-06-08  4:17 ` Vasant Hegde
2023-06-12 18:12 ` Jerry Snitselaar
2023-06-12 18:17 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).