Skip to contentSkip to conversation

iommu/arm-smmu-v3: Fix not checking return value about devm_add_action

PATCH In review Tian Tao 2 participants 2 messages Dec 8, 2020

Subsystems (2)
lore
Share & tools
lore

Tian Tao

author
#0 lore raw

PATCH v2 1/1 iommu/arm-smmu-v3: Fix not checking return value about devm_add_action

Use devm_add_action_or_reset to avoid the situation where the release function is not called when devm_add_action returns an error.

---
v2:
repositioning devm_add_action_or_reset in the function arm_smmu_setup_msis, and check the return value.

---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +9 -4
index 2ddf5ec..b4d3b7d 100644
@@ -2680,7 +2680,8 @@ static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu)
 		ret = -ENOMEM;
 	} else {
 		cmdq->valid_map = bitmap;
-		devm_add_action(smmu->dev, arm_smmu_cmdq_free_bitmap, bitmap);
+		ret = devm_add_action_or_reset(smmu->dev,
+					       arm_smmu_cmdq_free_bitmap, bitmap);
 	}
 
 	return ret;
@@ -2921,6 +2922,13 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
 		return;
 	}
 
+	/* Add callback to free MSIs on teardown */
+	ret = devm_add_action_or_reset(dev, arm_smmu_free_msis, dev);
+	if (ret) {
+		dev_warn(dev, "failed to add callback to free MSIs on teardown\n");
+		return;
+	}
+
 	for_each_msi_entry(desc, dev) {
 		switch (desc->platform.msi_index) {
 		case EVTQ_MSI_INDEX:
@@ -2936,9 +2944,6 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
 			continue;
 		}
 	}
-
-	/* Add callback to free MSIs on teardown */
-	devm_add_action(dev, arm_smmu_free_msis, dev);
 }
 
 static void arm_smmu_setup_unique_irqs(struct arm_smmu_device *smmu)
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer
#1 lore raw
Quoted 27 lines · Tian Tao

Use devm_add_action_or_reset to avoid the situation where the release function is not called when devm_add_action returns an error.

---
v2:
repositioning devm_add_action_or_reset in the function arm_smmu_setup_msis, and check the return value.

---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -1
index 2ddf5ec..b4d3b7d 100644
@@ -2680,7 +2680,8 @@ static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu)
 		ret = -ENOMEM;
 	} else {
 		cmdq->valid_map = bitmap;
-		devm_add_action(smmu->dev, arm_smmu_cmdq_free_bitmap, bitmap);
+		ret = devm_add_action_or_reset(smmu->dev,
+					       arm_smmu_cmdq_free_bitmap, bitmap);
 	}
 
 	return ret;

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_setup_msis(struct arm_smmu_device *smmu) · line 2929

Quoted 8 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +5 -0
@@ -2921,6 +2922,13 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
 		return;
 	}
 
+	/* Add callback to free MSIs on teardown */
+	ret = devm_add_action_or_reset(dev, arm_smmu_free_msis, dev);
+	if (ret) {
+		dev_warn(dev, "failed to add callback to free MSIs on teardown\n");
+		return;

Honestly, wouldn't we just be better leaking memory in this case? Tearing down the SMMU is a pretty specialist sport _anyway_, but this seems to throw the baby out with the bath water by failing to initialise because we can't defer freeing something that we've already allocated. I think we're better off continuing and trying to get the device up and running.

In fact, the same applies to the cmdq 'valid_map' too -- why do we care?

WIll
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu