Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH] iommu: Fix error unwind in iommu_group_alloc()
@ 2023-02-16  1:21 Jason Gunthorpe
  2023-02-16  2:38 ` Baolu Lu
  2023-02-16  9:21 ` Joerg Roedel
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2023-02-16  1:21 UTC (permalink / raw)
  To: iommu, Joerg Roedel, Robin Murphy, Will Deacon
  Cc: Bharat Bhushan, Eric Auger, Joerg Roedel, Olof Johansson,
	Tomasz Nowicki, Will Deacon

If either iommu_group_grate_file() fails then then the iommu_group
is leaked.

Destroy it on these error paths.

Found by kselftest/iommu/iommufd_fail_nth

Fixes: bc7d12b91bd3 ("iommu: Implement reserved_regions iommu-group sysfs file")
Fixes: c52c72d3dee8 ("iommu: Add sysfs attribyte for domain type")
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index dd9b60897c8673..e41c9df1504ba3 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -775,12 +775,16 @@ struct iommu_group *iommu_group_alloc(void)
 
 	ret = iommu_group_create_file(group,
 				      &iommu_group_attr_reserved_regions);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
 		return ERR_PTR(ret);
+	}
 
 	ret = iommu_group_create_file(group, &iommu_group_attr_type);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
 		return ERR_PTR(ret);
+	}
 
 	pr_debug("Allocated group %d\n", group->id);
 

base-commit: c643eb52cb7c1f6747ddc60d8a187a3ca0746a12
-- 
2.39.1


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

end of thread, other threads:[~2023-02-16  9:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16  1:21 [PATCH] iommu: Fix error unwind in iommu_group_alloc() Jason Gunthorpe
2023-02-16  2:38 ` Baolu Lu
2023-02-16  9:21 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox