diff mbox series

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

Message ID 20190706133021.3308-1-nishkadg.linux@gmail.com (mailing list archive)
State Mainlined
Commit 165d42c012be69900f0e2f8545626cb9e7d4a832
Headers show
Series gpu: drm: mediatek: mtk_drm_drv.c: Add of_node_put() before goto | expand

Commit Message

Nishka Dasgupta July 6, 2019, 1:30 p.m. UTC
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.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

CK Hu (胡俊光) Aug. 19, 2019, 1:30 a.m. UTC | #1
Hi, Nishka:

On Sat, 2019-07-06 at 19:00 +0530, Nishka Dasgupta wrote:
> 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

> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 95fdbd0fbcac..2dffbc8c6d73 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -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;
>  		}
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 95fdbd0fbcac..2dffbc8c6d73 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -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;
 		}