Skip to contentSkip to conversation

media: platform: mtk-mdp: mtk_mdp_core: Add of_node_put() before goto

PATCH In review Nishka Dasgupta 2 participants 2 messages Jul 9, 2019 – Jul 12, 2019

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

PATCH 1/1 media: platform: mtk-mdp: mtk_mdp_core: Add of_node_put() before goto

Each iteration of for_each_child_of_node puts the previous node, but in the case of a goto from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the goto in two places.
Issue found with Coccinelle.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_core.c +4 -1
index fc9faec85edb..d0a3f06ad83d 100644
@@ -145,13 +145,16 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 		comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
 		if (!comp) {
 			ret = -ENOMEM;
+			of_node_put(node);
 			goto err_comp;
 		}
 		mdp->comp[comp_id] = comp;
 
 		ret = mtk_mdp_comp_init(dev, node, comp, comp_id);
-		if (ret)
+		if (ret) {
+			of_node_put(node);
 			goto err_comp;
+		}
 	}
 
 	mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME);
Signature · 1 line
2.19.1
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous node, but in the case of a goto from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the goto in two places.
Issue found with Coccinelle.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_core.c +1 -0
index fc9faec85edb..d0a3f06ad83d 100644
@@ -145,13 +145,16 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 		comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
 		if (!comp) {
 			ret = -ENOMEM;
+			of_node_put(node);
 			goto err_comp;
 		}
 		mdp->comp[comp_id] = comp;

drivers/media/platform/mtk-mdp/mtk_mdp_core.c static int mtk_mdp_probe(struct platform_device *pdev) · line 160

Quoted 10 lines
drivers/media/platform/mtk-mdp/mtk_mdp_core.c +3 -1
 
 		ret = mtk_mdp_comp_init(dev, node, comp, comp_id);
-		if (ret)
+		if (ret) {
+			of_node_put(node);
 			goto err_comp;
+		}
 	}
 
 	mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME);

Thanks Nishka for fixing the bug.