2023-05-30 09:51:51

by Lu Hongfei

[permalink] [raw]
Subject: [PATCH] media: Fix resource leaks in for_each_child_of_node() loops

for_each_child_of_node should have of_node_put() avoid resource leaks.

Signed-off-by: Lu Hongfei <[email protected]>
---
drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 3 +++
1 file changed, 3 insertions(+)
mode change 100644 => 100755 drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c

diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
index 19a4a085f73a..5a6a61d68cba
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
@@ -1128,6 +1128,7 @@ int mdp_comp_config(struct mdp_dev *mdp)
comp = mdp_comp_create(mdp, node, id);
if (IS_ERR(comp)) {
ret = PTR_ERR(comp);
+ of_node_put(node);
goto err_init_comps;
}

@@ -1137,6 +1138,8 @@ int mdp_comp_config(struct mdp_dev *mdp)
pm_runtime_enable(comp->comp_dev);
}

+ of_node_put(node);
+
ret = mdp_comp_sub_create(mdp);
if (ret)
goto err_init_comps;
--
2.39.0



2023-07-19 07:51:53

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH] media: Fix resource leaks in for_each_child_of_node() loops

Hi Lu Hongfei,

Please add the driver name to the subject line: 'media: mdp3:'!

On 30/05/2023 11:45, Lu Hongfei wrote:
> for_each_child_of_node should have of_node_put() avoid resource leaks.
>
> Signed-off-by: Lu Hongfei <[email protected]>
> ---
> drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 3 +++
> 1 file changed, 3 insertions(+)
> mode change 100644 => 100755 drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
>
> diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> index 19a4a085f73a..5a6a61d68cba
> --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> @@ -1128,6 +1128,7 @@ int mdp_comp_config(struct mdp_dev *mdp)
> comp = mdp_comp_create(mdp, node, id);
> if (IS_ERR(comp)) {
> ret = PTR_ERR(comp);
> + of_node_put(node);

This is needed,

> goto err_init_comps;
> }
>
> @@ -1137,6 +1138,8 @@ int mdp_comp_config(struct mdp_dev *mdp)
> pm_runtime_enable(comp->comp_dev);
> }
>
> + of_node_put(node);
> +

but not this one. The for_each_child_of_node loop ended, so node == NULL and
there is nothing to put.

Regards,

Hans

> ret = mdp_comp_sub_create(mdp);
> if (ret)
> goto err_init_comps;