Skip to contentSkip to conversation

soc: qcom: ocmem: Fix refcount leak in of_get_ocmem

PATCH Applied Miaoqian Lin 3 participants 3 messages Jun 2, 2022 – Jul 3, 2022

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

PATCH 1/1 soc: qcom: ocmem: Fix refcount leak in of_get_ocmem

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. of_node_put() will check NULL pointer.

Fixes 88c1e9404f1d ("soc: qcom: add OCMEM driver")
---
 drivers/soc/qcom/ocmem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/soc/qcom/ocmem.c +3 -0
index 97fd24c178f8..c92d26b73e6f 100644
@@ -194,14 +194,17 @@ struct ocmem *of_get_ocmem(struct device *dev)
 	devnode = of_parse_phandle(dev->of_node, "sram", 0);
 	if (!devnode || !devnode->parent) {
 		dev_err(dev, "Cannot look up sram phandle\n");
+		of_node_put(devnode);
 		return ERR_PTR(-ENODEV);
 	}
 
 	pdev = of_find_device_by_node(devnode->parent);
 	if (!pdev) {
 		dev_err(dev, "Cannot find device node %s\n", devnode->name);
+		of_node_put(devnode);
 		return ERR_PTR(-EPROBE_DEFER);
 	}
+	of_node_put(devnode);
 
 	ocmem = platform_get_drvdata(pdev);
 	if (!ocmem) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Miaoqian Lin

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. of_node_put() will check NULL pointer.

Fixes 88c1e9404f1d ("soc: qcom: add OCMEM driver")
#2 lore raw

Re: (subset) [PATCH] soc: qcom: ocmem: Fix refcount leak in of_get_ocmem

In reply to Miaoqian Lin
Quoted 6 lines · Miaoqian Lin

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. of_node_put() will check NULL pointer.

Applied, thanks!

[1/1] soc: qcom: ocmem: Fix refcount leak in of_get_ocmem

      commit: 92a563fcf14b3093226fb36f12e9b5cf630c5a5d

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>