Skip to contentSkip to conversation

iommu/omap: Fix missing put_device() call in omap_iommu_probe_device

PATCH Superseded Miaoqian Lin 2 participants 6 messages Jan 7, 2022 – Mar 1, 2022 IOMMU

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/omap: Fix missing put_device() call in omap_iommu_probe_device

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 paths.

Fixes ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")
---
 drivers/iommu/omap-iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/omap-iommu.c +1 -0
index 91749654fd49..cbc7ca5e890a 100644
@@ -1684,6 +1684,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
 		oiommu = platform_get_drvdata(pdev);
 		if (!oiommu) {
 			of_node_put(np);
+			put_device(&pdev->dev);
 			kfree(arch_data);
 			return ERR_PTR(-EINVAL);
 		}
Signature · 6 lines
2.17.1

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

Hi Miaoqian,

Quoted 2 lines · Miaoqian Lin

The reference taken by 'of_find_device_by_node()' must be released when not needed anymore.

Thanks for catching this.

Quoted 1 line

Add the corresponding 'put_device()' in the error handling paths.

Also, need it in the regular path, not just in error handling path.

Quoted 12 lines
Fixes ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")
---
 drivers/iommu/omap-iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/omap-iommu.c +0 -0
index 91749654fd49..cbc7ca5e890a 100644

drivers/iommu/omap-iommu.c static struct iommu_device *omap_iommu_probe_device(struct device *dev) · line 1687

Quoted 4 lines
drivers/iommu/omap-iommu.c +1 -0
@@ -1684,6 +1684,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
 		oiommu = platform_get_drvdata(pdev);
 		if (!oiommu) {
 			of_node_put(np);
+			put_device(&pdev->dev);

nit, doesn't matter for functionality, but prefer the put_device before of_node_put().

regards
Suman

Quoted 4 lines
drivers/iommu/omap-iommu.c +0 -0
 			kfree(arch_data);
 			return ERR_PTR(-EINVAL);
 		}
#2 lore raw

Hi Suman Anna,

Quoted 6 lines · Suman Anna

Hi Miaoqian,

Quoted 1 line

Add the corresponding 'put_device()' in the error handling paths.

Also, need it in the regular path, not just in error handling path.

I think after calling platform_get_drvdata() normally, the reference will be released in other functions, so don't need it in the regular path.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#3 lore raw

Hi Miaoqian,

Quoted 5 lines · Miaoqian Lin

Hi Suman Anna,

Quoted 3 lines · Suman Anna

Hi Miaoqian,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Add the corresponding 'put_device()' in the error handling paths.

Also, need it in the regular path, not just in error handling path.

I think after calling platform_get_drvdata() normally, the reference will be released in other functions, so don't need it in the regular path.

No, it's a local reference and is acquired within omap_iommu_probe_device() and needs to be released within this function. What other function are you referring to here?

regards
Suman

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

#4 lore raw

Hi Suman,

Quoted 11 lines · Suman Anna

Hi Miaoqian,

Quoted 8 lines · Miaoqian Lin

Hi Suman Anna,

Quoted 6 lines · Suman Anna

Hi Miaoqian,

Quoted 1 line

Add the corresponding 'put_device()' in the error handling paths.

Also, need it in the regular path, not just in error handling path.

Quoted 9 lines
Quoted 4 lines

I think after calling platform_get_drvdata() normally, the reference will be released in other functions, so don't need it in the regular path.

No, it's a local reference and is acquired within omap_iommu_probe_device() and needs to be released within this function. What other function are you referring to here?

I am referring to the release function of this device, here is omap_iommu_release_device(). But I find omap_iommu_release_device() doesn't handle the reference, and calls kfree(arch_data) directly.

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

#5 lore raw

PATCH v2 1/1 iommu/omap: Fix missing put_device() call in omap_iommu_probe_device

In reply to Suman Anna

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 and the regular path.

Fixes ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")

---
changes in v2:
- move put_device() before of_node_put().
- add put_device() in the regular path.

---
 drivers/iommu/omap-iommu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/omap-iommu.c +2 -0
index 91749654fd49..2222b30a0a00 100644
@@ -1683,6 +1683,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
 
 		oiommu = platform_get_drvdata(pdev);
 		if (!oiommu) {
+			put_device(&pdev->dev);
 			of_node_put(np);
 			kfree(arch_data);
 			return ERR_PTR(-EINVAL);
@@ -1691,6 +1692,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
 		tmp->iommu_dev = oiommu;
 		tmp->dev = &pdev->dev;
 
+		put_device(&pdev->dev);
 		of_node_put(np);
 	}
 
Signature · 6 lines
2.17.1

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