[PATCH 1/2] iommu: fix memory leak of iopf

Longfang Liu liulongfang at huawei.com
Thu Oct 20 20:51:46 PDT 2022


In arm_smmu_init_queues(), if ARM_SMMU_FEAT_SVA and ARM_SMMU_FEAT_STALLS
are enabled, iopf will be allocated a queue memory, and after
arm_smmu_init_one_queue() processing fails, this part of iopf
memory is not released, and there is a memory leak problem.

Signed-off-by: Longfang Liu <liulongfang at huawei.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index b788a38d8fdf..a1db07bed6a9 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2939,9 +2939,13 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu)
 	if (!(smmu->features & ARM_SMMU_FEAT_PRI))
 		return 0;
 
-	return arm_smmu_init_one_queue(smmu, &smmu->priq.q, smmu->page1,
+	ret = arm_smmu_init_one_queue(smmu, &smmu->priq.q, smmu->page1,
 				       ARM_SMMU_PRIQ_PROD, ARM_SMMU_PRIQ_CONS,
 				       PRIQ_ENT_DWORDS, "priq");
+	if (ret)
+		iopf_queue_free(smmu->evtq.iopf);
+
+	return ret;
 }
 
 static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
-- 
2.24.0




More information about the linux-arm-kernel mailing list