[PATCH] iommu/rockchip: Clarify of_xlate

Robin Murphy robin.murphy at arm.com
Tue Dec 1 05:05:26 PST 2026


Technically "leaking" a reference on a platform device which will never
be freed anyway, and only under catastrophic OOM conditions, is entirely
a non-issue. But the number of attempts to "fix" it with additional
pointless checks is getting tiresome (and only made worse by LLMs...),
so let's just hoist the refcount drop up to avoid the offending pattern,
and add a comment on the general of_xlate flow for clarity.

Signed-off-by: Robin Murphy <robin.murphy at arm.com>
---
 drivers/iommu/rockchip-iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 21af2f621c76..4520f4fd139d 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1184,7 +1184,13 @@ static int rk_iommu_of_xlate(struct device *dev,
 	struct platform_device *iommu_dev;
 	struct rk_iommudata *data;
 
+	/*
+	 * If we're here at all it's because args->np matched what we passed to
+	 * iommu_device_register(), so iommu_dev is by definition valid and
+	 * referenced already since this driver is currently bound to it!
+	 */
 	iommu_dev = of_find_device_by_node(args->np);
+	platform_device_put(iommu_dev);
 
 	data = devm_kzalloc(&iommu_dev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -1193,8 +1199,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 	data->iommu = platform_get_drvdata(iommu_dev);
 	dev_iommu_priv_set(dev, data);
 
-	platform_device_put(iommu_dev);
-
 	return 0;
 }
 
-- 
2.54.0.dirty




More information about the Linux-rockchip mailing list