Skip to contentSkip to conversation

iommu: Optimize the error handling when allocating an iommu group

PATCH New Baolin Wang 1 participant 1 message Jun 1, 2020 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu: Optimize the error handling when allocating an iommu group

Optimize the error handling to free the resources correctly when failed to allocate an iommu group.

---
 drivers/iommu/iommu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +8 -2
index 03d6a26..ac91024 100644
@@ -529,12 +529,18 @@ 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) {
+		iommu_group_remove_file(group,
+					&iommu_group_attr_reserved_regions);
+		kobject_put(group->devices_kobj);
 		return ERR_PTR(ret);
+	}
 
 	pr_debug("Allocated group %d\n", group->id);
 
Signature · 1 line
1.8.3.1