diff mbox series

video: fbdev: amba-clcd: Fix refcount leak bugs

Message ID 20220719082546.1209627-1-windhl@126.com
State New
Headers show
Series video: fbdev: amba-clcd: Fix refcount leak bugs | expand

Commit Message

Liang He July 19, 2022, 8:25 a.m. UTC
In clcdfb_of_init_display(), we should call of_node_put() for the
references returned by of_graph_get_next_endpoint() and
of_graph_get_remote_port_parent() which have increased the refcount.

Besides, we should call of_node_put() both in fail path or when
the references are not used anymore.

Fixes: d10715be03bd ("video: ARM CLCD: Add DT support")
Signed-off-by: Liang He <windhl@126.com>
---
 drivers/video/fbdev/amba-clcd.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Comments

Helge Deller July 26, 2022, 6:56 a.m. UTC | #1
On 7/19/22 10:25, Liang He wrote:
> In clcdfb_of_init_display(), we should call of_node_put() for the
> references returned by of_graph_get_next_endpoint() and
> of_graph_get_remote_port_parent() which have increased the refcount.
>
> Besides, we should call of_node_put() both in fail path or when
> the references are not used anymore.
>
> Fixes: d10715be03bd ("video: ARM CLCD: Add DT support")
> Signed-off-by: Liang He <windhl@126.com>

applied.
Thanks!
Helge

> ---
>  drivers/video/fbdev/amba-clcd.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/video/fbdev/amba-clcd.c b/drivers/video/fbdev/amba-clcd.c
> index 8080116aea84..f65c96d1394d 100644
> --- a/drivers/video/fbdev/amba-clcd.c
> +++ b/drivers/video/fbdev/amba-clcd.c
> @@ -698,16 +698,18 @@ static int clcdfb_of_init_display(struct clcd_fb *fb)
>  		return -ENODEV;
>
>  	panel = of_graph_get_remote_port_parent(endpoint);
> -	if (!panel)
> -		return -ENODEV;
> +	if (!panel) {
> +		err = -ENODEV;
> +		goto out_endpoint_put;
> +	}
>
>  	err = clcdfb_of_get_backlight(&fb->dev->dev, fb->panel);
>  	if (err)
> -		return err;
> +		goto out_panel_put;
>
>  	err = clcdfb_of_get_mode(&fb->dev->dev, panel, fb->panel);
>  	if (err)
> -		return err;
> +		goto out_panel_put;
>
>  	err = of_property_read_u32(fb->dev->dev.of_node, "max-memory-bandwidth",
>  			&max_bandwidth);
> @@ -736,11 +738,21 @@ static int clcdfb_of_init_display(struct clcd_fb *fb)
>
>  	if (of_property_read_u32_array(endpoint,
>  			"arm,pl11x,tft-r0g0b0-pads",
> -			tft_r0b0g0, ARRAY_SIZE(tft_r0b0g0)) != 0)
> -		return -ENOENT;
> +			tft_r0b0g0, ARRAY_SIZE(tft_r0b0g0)) != 0) {
> +		err = -ENOENT;
> +		goto out_panel_put;
> +	}
> +
> +	of_node_put(panel);
> +	of_node_put(endpoint);
>
>  	return clcdfb_of_init_tft_panel(fb, tft_r0b0g0[0],
>  					tft_r0b0g0[1],  tft_r0b0g0[2]);
> +out_panel_put:
> +	of_node_put(panel);
> +out_endpoint_put:
> +	of_node_put(endpoint);
> +	return err;
>  }
>
>  static int clcdfb_of_vram_setup(struct clcd_fb *fb)
diff mbox series

Patch

diff --git a/drivers/video/fbdev/amba-clcd.c b/drivers/video/fbdev/amba-clcd.c
index 8080116aea84..f65c96d1394d 100644
--- a/drivers/video/fbdev/amba-clcd.c
+++ b/drivers/video/fbdev/amba-clcd.c
@@ -698,16 +698,18 @@  static int clcdfb_of_init_display(struct clcd_fb *fb)
 		return -ENODEV;
 
 	panel = of_graph_get_remote_port_parent(endpoint);
-	if (!panel)
-		return -ENODEV;
+	if (!panel) {
+		err = -ENODEV;
+		goto out_endpoint_put;
+	}
 
 	err = clcdfb_of_get_backlight(&fb->dev->dev, fb->panel);
 	if (err)
-		return err;
+		goto out_panel_put;
 
 	err = clcdfb_of_get_mode(&fb->dev->dev, panel, fb->panel);
 	if (err)
-		return err;
+		goto out_panel_put;
 
 	err = of_property_read_u32(fb->dev->dev.of_node, "max-memory-bandwidth",
 			&max_bandwidth);
@@ -736,11 +738,21 @@  static int clcdfb_of_init_display(struct clcd_fb *fb)
 
 	if (of_property_read_u32_array(endpoint,
 			"arm,pl11x,tft-r0g0b0-pads",
-			tft_r0b0g0, ARRAY_SIZE(tft_r0b0g0)) != 0)
-		return -ENOENT;
+			tft_r0b0g0, ARRAY_SIZE(tft_r0b0g0)) != 0) {
+		err = -ENOENT;
+		goto out_panel_put;
+	}
+
+	of_node_put(panel);
+	of_node_put(endpoint);
 
 	return clcdfb_of_init_tft_panel(fb, tft_r0b0g0[0],
 					tft_r0b0g0[1],  tft_r0b0g0[2]);
+out_panel_put:
+	of_node_put(panel);
+out_endpoint_put:
+	of_node_put(endpoint);
+	return err;
 }
 
 static int clcdfb_of_vram_setup(struct clcd_fb *fb)