* [PATCH] iommu: fix resource leak in iommu_group_alloc
@ 2022-08-29 7:11 Yuan Can
0 siblings, 0 replies; only message in thread
From: Yuan Can @ 2022-08-29 7:11 UTC (permalink / raw)
To: joro, will, robin.murphy, iommu; +Cc: linux-kernel, yuancan
When it fails to create file for reserved_regions and type
of an iommu_group, the iommu_group_alloc returns ERR_PTR
without releasing the iommu_group.
Add error handling to cleanup leaking resources.
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
drivers/iommu/iommu.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 1ca59afc8472..fff23231b5fc 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -675,15 +675,22 @@ struct iommu_group *iommu_group_alloc(void)
ret = iommu_group_create_file(group,
&iommu_group_attr_reserved_regions);
if (ret)
- return ERR_PTR(ret);
+ goto out_put_group;
ret = iommu_group_create_file(group, &iommu_group_attr_type);
if (ret)
- return ERR_PTR(ret);
+ goto out_remove_file;
pr_debug("Allocated group %d\n", group->id);
return group;
+
+out_remove_file:
+ iommu_group_remove_file(group, &iommu_group_attr_reserved_regions);
+out_put_group:
+ iommu_group_put(group);
+
+ return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(iommu_group_alloc);
--
2.17.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-29 7:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 7:11 [PATCH] iommu: fix resource leak in iommu_group_alloc Yuan Can
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).