Skip to contentSkip to conversation

iommu/tegra-smmu: Fix missing put_device() call in tegra_smmu_find

PATCH In review Miaoqian Lin 3 participants 4 messages Jan 7, 2022 – Feb 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/tegra-smmu: Fix missing put_device() call in tegra_smmu_find

The reference taken by 'of_find_device_by_node()' must be released when not needed anymore.
Add the corresponding 'put_device()' in the error handling path.

Fixes 765a9d1d02b2 ("iommu/tegra-smmu: Fix mc errors on tegra124-nyan")
---
 drivers/iommu/tegra-smmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/tegra-smmu.c +3 -1
index e900e3c46903..2561ce8a2ce8 100644
@@ -808,8 +808,10 @@ static struct tegra_smmu *tegra_smmu_find(struct device_node *np)
 		return NULL;
 
 	mc = platform_get_drvdata(pdev);
-	if (!mc)
+	if (!mc) {
+		put_device(&pdev->dev);
 		return NULL;
+	}
 
 	return mc->smmu;
 }
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Thierry,

does this look correct to you?

Thanks,

Joerg

Quoted 28 lines · Miaoqian Lin

The reference taken by 'of_find_device_by_node()' must be released when not needed anymore.
Add the corresponding 'put_device()' in the error handling path.

Fixes 765a9d1d02b2 ("iommu/tegra-smmu: Fix mc errors on tegra124-nyan")
---
 drivers/iommu/tegra-smmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/tegra-smmu.c +3 -1
index e900e3c46903..2561ce8a2ce8 100644
@@ -808,8 +808,10 @@ static struct tegra_smmu *tegra_smmu_find(struct device_node *np)
 		return NULL;
 
 	mc = platform_get_drvdata(pdev);
-	if (!mc)
+	if (!mc) {
+		put_device(&pdev->dev);
 		return NULL;
+	}
 
 	return mc->smmu;
 }
Signature · 1 line
2.17.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Acked-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 16 lines · Miaoqian Lin

The reference taken by 'of_find_device_by_node()' must be released when not needed anymore.
Add the corresponding 'put_device()' in the error handling path.

Fixes 765a9d1d02b2 ("iommu/tegra-smmu: Fix mc errors on tegra124-nyan")
---
 drivers/iommu/tegra-smmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/tegra-smmu.c +0 -0
index e900e3c46903..2561ce8a2ce8 100644
@@ -808,8 +808,10 @@ static struct tegra_smmu *tegra_smmu_find(struct device_node *np)
 		return NULL;

drivers/iommu/tegra-smmu.c static struct tegra_smmu *tegra_smmu_find(struct device_node *np) · line 817

Quoted 10 lines
drivers/iommu/tegra-smmu.c +3 -1
 
 	mc = platform_get_drvdata(pdev);
-	if (!mc)
+	if (!mc) {
+		put_device(&pdev->dev);
 		return NULL;
+	}
 
 	return mc->smmu;
 }

Sorry for the late reply, looks correct. We probably also need a similar call in ->release_device(). I also wonder if we should be returning an -EPROBE_DEFER here, which is technically the correct thing to do, though in practice that will likely never happen because these pointers are set during an arch_initcall, so should always be available by the time a driver tries to attach to an IOMMU.

maintainer
#3 lore raw
In reply to Miaoqian Lin
Quoted 9 lines · Miaoqian Lin

The reference taken by 'of_find_device_by_node()' must be released when not needed anymore.
Add the corresponding 'put_device()' in the error handling path.

Fixes 765a9d1d02b2 ("iommu/tegra-smmu: Fix mc errors on tegra124-nyan")
---
 drivers/iommu/tegra-smmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied for v5.17, thanks.