diff mbox series

[2/2] drm/mediatek: Switch to for_each_child_of_node_scoped()

Message ID 20241011-mtk_drm_drv_memleak-v1-2-2b40c74c8d75@gmail.com (mailing list archive)
State New
Headers show
Series drm/mediatek: Fix child node refcount handling and use scoped macro | expand

Commit Message

Javier Carrasco Oct. 11, 2024, 7:21 p.m. UTC
Introduce the scoped variant of the loop to automatically release the
child node when it goes out of scope, which is more robust than the
non-scoped variant, and accounts for new early exits that could be added
in the future.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

CK Hu (胡俊光) Oct. 23, 2024, 2:50 a.m. UTC | #1
Hi, Javier:

On Fri, 2024-10-11 at 21:21 +0200, Javier Carrasco wrote:
>  	 
> External email : Please do not click links or open attachments until you have verified the sender or the content.
>  Introduce the scoped variant of the loop to automatically release the
> child node when it goes out of scope, which is more robust than the
> non-scoped variant, and accounts for new early exits that could be added
> in the future.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 0878df832859..9ab656b10a49 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -372,12 +372,11 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
>  struct mtk_drm_private *temp_drm_priv;
>  struct device_node *phandle = dev->parent->of_node;
>  const struct of_device_id *of_id;
> -struct device_node *node;
>  struct device *drm_dev;
>  unsigned int cnt = 0;
>  int i, j;
>  
> -for_each_child_of_node(phandle->parent, node) {
> +for_each_child_of_node_scoped(phandle->parent, node) {
>  struct platform_device *pdev;
>  
>  of_id = of_match_node(mtk_drm_of_ids, node);
> @@ -406,10 +405,8 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
>  if (temp_drm_priv->mtk_drm_bound)
>  cnt++;
>  
> -if (cnt == MAX_CRTC) {
> -of_node_put(node);
> +if (cnt == MAX_CRTC)
>  break;
> -}
>  }
>  
>  if (drm_priv->data->mmsys_dev_num == cnt) {
> 
> -- 
> 2.43.0
>
Chen-Yu Tsai Oct. 28, 2024, 7 a.m. UTC | #2
On Sat, Oct 12, 2024 at 3:22 AM Javier Carrasco
<javier.carrasco.cruz@gmail.com> wrote:
>
> Introduce the scoped variant of the loop to automatically release the
> child node when it goes out of scope, which is more robust than the
> non-scoped variant, and accounts for new early exits that could be added
> in the future.
>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
AngeloGioacchino Del Regno Oct. 28, 2024, 9:09 a.m. UTC | #3
Il 11/10/24 21:21, Javier Carrasco ha scritto:
> Introduce the scoped variant of the loop to automatically release the
> child node when it goes out of scope, which is more robust than the
> non-scoped variant, and accounts for new early exits that could be added
> in the future.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
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 0878df832859..9ab656b10a49 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -372,12 +372,11 @@  static bool mtk_drm_get_all_drm_priv(struct device *dev)
 	struct mtk_drm_private *temp_drm_priv;
 	struct device_node *phandle = dev->parent->of_node;
 	const struct of_device_id *of_id;
-	struct device_node *node;
 	struct device *drm_dev;
 	unsigned int cnt = 0;
 	int i, j;
 
-	for_each_child_of_node(phandle->parent, node) {
+	for_each_child_of_node_scoped(phandle->parent, node) {
 		struct platform_device *pdev;
 
 		of_id = of_match_node(mtk_drm_of_ids, node);
@@ -406,10 +405,8 @@  static bool mtk_drm_get_all_drm_priv(struct device *dev)
 		if (temp_drm_priv->mtk_drm_bound)
 			cnt++;
 
-		if (cnt == MAX_CRTC) {
-			of_node_put(node);
+		if (cnt == MAX_CRTC)
 			break;
-		}
 	}
 
 	if (drm_priv->data->mmsys_dev_num == cnt) {