LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device()
@ 2023-12-13 11:07 Harshit Mogalapalli
  2023-12-13 11:13 ` Harshit Mogalapalli
  0 siblings, 1 reply; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-12-13 11:07 UTC (permalink / raw
  To: Joerg Roedel, iommu, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27, harshit.m.mogalapalli

Free the handle when the domain allocation fails before unlocking and
returning.

Fixes: 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is based on static analysis with smatch, only compile tested.
---
 drivers/iommu/iommu-sva.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 5175e8d85247..c3fc9201d0be 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -101,7 +101,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 	domain = iommu_sva_domain_alloc(dev, mm);
 	if (!domain) {
 		ret = -ENOMEM;
-		goto out_unlock;
+		goto out_free_handle;
 	}
 
 	ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid);
@@ -118,6 +118,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 
 out_free_domain:
 	iommu_domain_free(domain);
+out_free_handle:
 	kfree(handle);
 out_unlock:
 	mutex_unlock(&iommu_sva_lock);
-- 
2.39.3


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

* Re: [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device()
  2023-12-13 11:07 Harshit Mogalapalli
@ 2023-12-13 11:13 ` Harshit Mogalapalli
  0 siblings, 0 replies; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-12-13 11:13 UTC (permalink / raw
  To: Joerg Roedel, iommu, linux-kernel; +Cc: dan.carpenter, kernel-janitors, error27

Hi,
On 13/12/23 4:37 pm, Harshit Mogalapalli wrote:
> Free the handle when the domain allocation fails before unlocking and
> returning.
> 

Please ignore this patch, I have missed CCing correct list and few 
maintainers, will resend it correctly.

Thanks,
Harshit
> Fixes: 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> This is based on static analysis with smatch, only compile tested.
> ---
>   drivers/iommu/iommu-sva.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> index 5175e8d85247..c3fc9201d0be 100644
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c
> @@ -101,7 +101,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
>   	domain = iommu_sva_domain_alloc(dev, mm);
>   	if (!domain) {
>   		ret = -ENOMEM;
> -		goto out_unlock;
> +		goto out_free_handle;
>   	}
>   
>   	ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid);
> @@ -118,6 +118,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
>   
>   out_free_domain:
>   	iommu_domain_free(domain);
> +out_free_handle:
>   	kfree(handle);
>   out_unlock:
>   	mutex_unlock(&iommu_sva_lock);


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

* [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device()
@ 2023-12-13 11:14 Harshit Mogalapalli
  2023-12-13 13:26 ` Baolu Lu
  2023-12-15  8:07 ` Joerg Roedel
  0 siblings, 2 replies; 5+ messages in thread
From: Harshit Mogalapalli @ 2023-12-13 11:14 UTC (permalink / raw
  To: Joerg Roedel, Will Deacon, Robin Murphy, iommu, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27, harshit.m.mogalapalli

Free the handle when the domain allocation fails before unlocking and
returning.

Fixes: 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is based on static analysis with smatch, only compile tested.
---
 drivers/iommu/iommu-sva.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 5175e8d85247..c3fc9201d0be 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -101,7 +101,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 	domain = iommu_sva_domain_alloc(dev, mm);
 	if (!domain) {
 		ret = -ENOMEM;
-		goto out_unlock;
+		goto out_free_handle;
 	}
 
 	ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid);
@@ -118,6 +118,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 
 out_free_domain:
 	iommu_domain_free(domain);
+out_free_handle:
 	kfree(handle);
 out_unlock:
 	mutex_unlock(&iommu_sva_lock);
-- 
2.39.3


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

* Re: [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device()
  2023-12-13 11:14 [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device() Harshit Mogalapalli
@ 2023-12-13 13:26 ` Baolu Lu
  2023-12-15  8:07 ` Joerg Roedel
  1 sibling, 0 replies; 5+ messages in thread
From: Baolu Lu @ 2023-12-13 13:26 UTC (permalink / raw
  To: Harshit Mogalapalli, Joerg Roedel, Will Deacon, Robin Murphy,
	iommu, linux-kernel
  Cc: baolu.lu, dan.carpenter, kernel-janitors, error27

On 2023/12/13 19:14, Harshit Mogalapalli wrote:
> Free the handle when the domain allocation fails before unlocking and
> returning.
> 
> Fixes: 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")
> Signed-off-by: Harshit Mogalapalli<harshit.m.mogalapalli@oracle.com>

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu

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

* Re: [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device()
  2023-12-13 11:14 [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device() Harshit Mogalapalli
  2023-12-13 13:26 ` Baolu Lu
@ 2023-12-15  8:07 ` Joerg Roedel
  1 sibling, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2023-12-15  8:07 UTC (permalink / raw
  To: Harshit Mogalapalli
  Cc: Will Deacon, Robin Murphy, iommu, linux-kernel, dan.carpenter,
	kernel-janitors, error27

On Wed, Dec 13, 2023 at 03:14:50AM -0800, Harshit Mogalapalli wrote:
>  drivers/iommu/iommu-sva.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks.

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

end of thread, other threads:[~2023-12-15  8:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-13 11:14 [PATCH] iommu/sva: Fix memory leak in iommu_sva_bind_device() Harshit Mogalapalli
2023-12-13 13:26 ` Baolu Lu
2023-12-15  8:07 ` Joerg Roedel
  -- strict thread matches above, loose matches on Subject: below --
2023-12-13 11:07 Harshit Mogalapalli
2023-12-13 11:13 ` Harshit Mogalapalli

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 read-only IMAP folder(s) and NNTP newsgroup(s).