Skip to content

Commit 99e675d

Browse files
Guoqing Jiangjoergroedel
authored andcommitted
iommu/vt-d: Fix potential memory leak in intel_setup_irq_remapping()
After commit e3beca4 ("irqdomain/treewide: Keep firmware node unconditionally allocated"). For tear down scenario, fn is only freed after fail to allocate ir_domain, though it also should be freed in case dmar_enable_qi returns error. Besides free fn, irq_domain and ir_msi_domain need to be removed as well if intel_setup_irq_remapping fails to enable queued invalidation. Improve the rewinding path by add out_free_ir_domain and out_free_fwnode lables per Baolu's suggestion. Fixes: e3beca4 ("irqdomain/treewide: Keep firmware node unconditionally allocated") Suggested-by: Lu Baolu <[email protected]> Signed-off-by: Guoqing Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 30209b9 commit 99e675d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/iommu/intel/irq_remapping.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,8 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
569569
fn, &intel_ir_domain_ops,
570570
iommu);
571571
if (!iommu->ir_domain) {
572-
irq_domain_free_fwnode(fn);
573572
pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id);
574-
goto out_free_bitmap;
573+
goto out_free_fwnode;
575574
}
576575
iommu->ir_msi_domain =
577576
arch_create_remap_msi_irq_domain(iommu->ir_domain,
@@ -595,7 +594,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
595594

596595
if (dmar_enable_qi(iommu)) {
597596
pr_err("Failed to enable queued invalidation\n");
598-
goto out_free_bitmap;
597+
goto out_free_ir_domain;
599598
}
600599
}
601600

@@ -619,6 +618,14 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
619618

620619
return 0;
621620

621+
out_free_ir_domain:
622+
if (iommu->ir_msi_domain)
623+
irq_domain_remove(iommu->ir_msi_domain);
624+
iommu->ir_msi_domain = NULL;
625+
irq_domain_remove(iommu->ir_domain);
626+
iommu->ir_domain = NULL;
627+
out_free_fwnode:
628+
irq_domain_free_fwnode(fn);
622629
out_free_bitmap:
623630
bitmap_free(bitmap);
624631
out_free_pages:

0 commit comments

Comments
 (0)