Skip to contentSkip to conversation

gpu: drm: mediatek: mtk_drm_drv.c: Add of_node_put() before goto

PATCH Applied Nishka Dasgupta 2 participants 2 messages Jul 6, 2019 – Aug 19, 2019

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

PATCH 1/1 gpu: drm: mediatek: mtk_drm_drv.c: 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/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +4 -1
index 95fdbd0fbcac..2dffbc8c6d73 100644
@@ -524,12 +524,15 @@ static int mtk_drm_probe(struct platform_device *pdev)
 			comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
 			if (!comp) {
 				ret = -ENOMEM;
+				of_node_put(node);
 				goto err_node;
 			}
 
 			ret = mtk_ddp_comp_init(dev, node, comp, comp_id, NULL);
-			if (ret)
+			if (ret) {
+				of_node_put(node);
 				goto err_node;
+			}
 
 			private->ddp_comp[comp_id] = comp;
 		}
Signature · 1 line
2.19.1
Applied
#1 lore raw

Hi, Nishka:

Quoted 5 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.

Applied to mediatek-drm-fixes-5.3 [1], thanks.

[1]
https://github.com/ckhu-mediatek/linux.git-tags/tree/mediatek-drm-fixes-5.3

Regards,
CK

Quoted 17 lines
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +1 -0
index 95fdbd0fbcac..2dffbc8c6d73 100644
@@ -524,12 +524,15 @@ static int mtk_drm_probe(struct platform_device *pdev)
 			comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
 			if (!comp) {
 				ret = -ENOMEM;
+				of_node_put(node);
 				goto err_node;
 			}

drivers/gpu/drm/mediatek/mtk_drm_drv.c static int mtk_drm_probe(struct platform_device *pdev) · line 538

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3 -1
 
 			ret = mtk_ddp_comp_init(dev, node, comp, comp_id, NULL);
-			if (ret)
+			if (ret) {
+				of_node_put(node);
 				goto err_node;
+			}
 
 			private->ddp_comp[comp_id] = comp;
 		}

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel