iommu/sva: Fix memory leak in iommu_sva_bind_device()

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

Fixes: 092edaddb6 ("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>
Link: https://lore.kernel.org/r/20231213111450.2487861-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
Harshit Mogalapalli 2023-12-13 03:14:50 -08:00 committed by Joerg Roedel
parent a63c357b9f
commit 9991a82a38
1 changed files with 2 additions and 1 deletions

View File

@ -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 @@ out:
out_free_domain:
iommu_domain_free(domain);
out_free_handle:
kfree(handle);
out_unlock:
mutex_unlock(&iommu_sva_lock);