[PATCH] iommu/rockchip: Fix platform device reference leak in rk_iommu_of_xlate()
From: Wentao Liang
Date: Thu Sep 17 2026 - 01:32:43 EST
From: Wentao Liang <vulab@xxxxxxxxxxx>
of_find_device_by_node() returns the platform device with an elevated
reference count, which is dropped on the success path only. If the
devm_kzalloc() for the per-device data fails, the error return leaks
that reference.
Put the device reference on the error path too.
Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/iommu/rockchip-iommu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 0013cf196c57..05a4fa227847 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1165,8 +1165,10 @@ static int rk_iommu_of_xlate(struct device *dev,
iommu_dev = of_find_device_by_node(args->np);
data = devm_kzalloc(&iommu_dev->dev, sizeof(*data), GFP_KERNEL);
- if (!data)
+ if (!data) {
+ platform_device_put(iommu_dev);
return -ENOMEM;
+ }
data->iommu = platform_get_drvdata(iommu_dev);
dev_iommu_priv_set(dev, data);
--
2.34.1