Skip to contentSkip to conversation

iommu/arm-smmu-v3: Revert vmaster in the error path

PATCH Superseded Nicolin Chen 3 participants 4 messages Jul 10, 2025 – Jul 11, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/arm-smmu-v3: Revert vmaster in the error path

The error path in the arm_smmu_attach_prepare() was introduced with the arm_smmu_enable_iopf(). Due to a rebase issue, it forgot to include the revert of the vmaster.

Move kfree(state->vmaster) to the error path, to prevent memory leak.

Fixes cfea71aea921 ("iommu/arm-smmu-v3: Put iopf enablement in the domain attach path")
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4 -3
index 181d07bc1a9d..3c79cdbbd9e7 100644
@@ -2906,8 +2906,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 
 		master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL);
 		if (!master_domain) {
-			kfree(state->vmaster);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto err_free_vmaster;
 		}
 		master_domain->domain = new_domain;
 		master_domain->master = master;
@@ -2941,7 +2941,6 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 		    !arm_smmu_master_canwbs(master)) {
 			spin_unlock_irqrestore(&smmu_domain->devices_lock,
 					       flags);
-			kfree(state->vmaster);
 			ret = -EINVAL;
 			goto err_iopf;
 		}
@@ -2967,6 +2966,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 	arm_smmu_disable_iopf(master, master_domain);
 err_free_master_domain:
 	kfree(master_domain);
+err_free_vmaster:
+	kfree(state->vmaster);
 	return ret;
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Nicolin Chen

The error path in the arm_smmu_attach_prepare() was introduced with the arm_smmu_enable_iopf(). Due to a rebase issue, it forgot to include the revert of the vmaster.

Move kfree(state->vmaster) to the error path, to prevent memory leak.

Fixes cfea71aea921 ("iommu/arm-smmu-v3: Put iopf enablement in the domain attach path")

Thanks!
Praan

Quoted 40 lines
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4 -3
index 181d07bc1a9d..3c79cdbbd9e7 100644
@@ -2906,8 +2906,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 
 		master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL);
 		if (!master_domain) {
-			kfree(state->vmaster);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto err_free_vmaster;
 		}
 		master_domain->domain = new_domain;
 		master_domain->master = master;
@@ -2941,7 +2941,6 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 		    !arm_smmu_master_canwbs(master)) {
 			spin_unlock_irqrestore(&smmu_domain->devices_lock,
 					       flags);
-			kfree(state->vmaster);
 			ret = -EINVAL;
 			goto err_iopf;
 		}
@@ -2967,6 +2966,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
 	arm_smmu_disable_iopf(master, master_domain);
 err_free_master_domain:
 	kfree(master_domain);
+err_free_vmaster:
+	kfree(state->vmaster);
 	return ret;
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Nicolin Chen
Quoted 4 lines · Nicolin Chen

The error path in the arm_smmu_attach_prepare() was introduced with the arm_smmu_enable_iopf(). Due to a rebase issue, it forgot to include the revert of the vmaster.

Quoted 8 lines

Move kfree(state->vmaster) to the error path, to prevent memory leak.

Fixes cfea71aea921 ("iommu/arm-smmu-v3: Put iopf enablement in the domain attach path")
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

The patch is fine but the commit message is a bit confusing

The error path for err_free_master_domain leaks the vmaster. Move all the kfrees for vmaster into the goto error section..

Jason

#3 lore raw
Quoted 14 lines · Jason Gunthorpe
Quoted 4 lines · Nicolin Chen

The error path in the arm_smmu_attach_prepare() was introduced with the arm_smmu_enable_iopf(). Due to a rebase issue, it forgot to include the revert of the vmaster.

Quoted 8 lines

Move kfree(state->vmaster) to the error path, to prevent memory leak.

Fixes cfea71aea921 ("iommu/arm-smmu-v3: Put iopf enablement in the domain attach path")
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 6 lines

The patch is fine but the commit message is a bit confusing

The error path for err_free_master_domain leaks the vmaster. Move all the kfrees for vmaster into the goto error section..

OK. I will respin one fixing that.

Thanks!
Nicolin