mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iommu/msm: unwind probe state on registration failure
@ 2026-07-16  1:32 Weimin Xiong
  2026-07-16  7:27 ` Mukesh Ojha
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Weimin Xiong @ 2026-07-16  1:32 UTC (permalink / raw)
  To: robin.clark, joro, will, robin.murphy
  Cc: linux-arm-msm, iommu, linux-kernel, Weimin Xiong, stable

msm_iommu_probe() adds its devm-managed IOMMU object to
qcom_iommu_devices before adding the IOMMU sysfs device and registering
it with the IOMMU core.

If iommu_device_sysfs_add() fails, probe returns with the object still on
qcom_iommu_devices. The driver core then releases the devm allocation,
leaving a dangling list entry that later list walks may dereference.

If iommu_device_register() fails, the same dangling list entry remains
and the sysfs device is left registered as well.

Unwind the sysfs device and global list entry in reverse setup order on
the corresponding failure paths.

Fixes: 42df43b36163 ("iommu/msm: Make use of iommu_device_register interface")
Cc: stable@vger.kernel.org
Signed-off-by: Weimin Xiong <xiongwm2026@163.com>
---
Changes in v2:
- Resend the former patch 4/4 independently; patches 1-3 from v1 are
  dropped.
- Explain the dangling list entry and stale sysfs device consequences.
- Add Fixes and stable tags.
- No code changes.

v1: https://lore.kernel.org/r/20260714060930.220277-5-xiongwm2026@163.com

 drivers/iommu/msm_iommu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 0ad5ff431..d0d926be7 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -784,19 +784,25 @@ static int msm_iommu_probe(struct platform_device *pdev)
 				     "msm-smmu.%pa", &ioaddr);
 	if (ret) {
 		pr_err("Could not add msm-smmu at %pa to sysfs\n", &ioaddr);
-		return ret;
+		goto err_remove_list;
 	}
 
 	ret = iommu_device_register(&iommu->iommu, &msm_iommu_ops, &pdev->dev);
 	if (ret) {
 		pr_err("Could not register msm-smmu at %pa\n", &ioaddr);
-		return ret;
+		goto err_remove_sysfs;
 	}
 
 	pr_info("device mapped at %p, irq %d with %d ctx banks\n",
 		iommu->base, iommu->irq, iommu->ncb);
 
 	return ret;
+
+err_remove_sysfs:
+	iommu_device_sysfs_remove(&iommu->iommu);
+err_remove_list:
+	list_del(&iommu->dev_node);
+	return ret;
 }
 
 static const struct of_device_id msm_iommu_dt_match[] = {


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-16 12:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-16  1:32 [PATCH v2] iommu/msm: unwind probe state on registration failure Weimin Xiong
2026-07-16  7:27 ` Mukesh Ojha
2026-07-16  8:53 ` [PATCH v3] iommu/msm: Fix dangling list entry on probe failure Weimin Xiong
2026-07-16  9:42   ` Konrad Dybcio
2026-07-16 12:05     ` Robin Murphy
2026-07-16 12:19       ` Mukesh Ojha
2026-07-16 12:26 ` [PATCH v2] iommu/msm: unwind probe state on registration failure Mukesh Ojha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox