[v2] drm: rcar-du: fix possible object reference leak
diff mbox series

Message ID 1554692313-28882-3-git-send-email-wen.yang99@zte.com.cn
State New
Delegated to: Kieran Bingham
Headers show
Series
  • [v2] drm: rcar-du: fix possible object reference leak
Related show

Commit Message

Wen Yang April 8, 2019, 2:58 a.m. UTC
The call to of_get_parent returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
drivers/gpu/drm/rcar-du/rcar_du_of.c:235:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 216, but without a corresponding object release within this function.
drivers/gpu/drm/rcar-du/rcar_du_of.c:236:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 209, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org (open list)
---
v2->v1: turn the return into a goto done.

 drivers/gpu/drm/rcar-du/rcar_du_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mukesh Ojha April 8, 2019, 8:45 a.m. UTC | #1
On 4/8/2019 8:28 AM, Wen Yang wrote:
> The call to of_get_parent returns a node pointer with refcount
> incremented thus it must be explicitly decremented after the last
> usage.
>
> Detected by coccinelle with the following warnings:
> drivers/gpu/drm/rcar-du/rcar_du_of.c:235:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 216, but without a corresponding object release within this function.
> drivers/gpu/drm/rcar-du/rcar_du_of.c:236:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 209, but without a corresponding object release within this function.
>
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org (open list)
> ---
> v2->v1: turn the return into a goto done.
>
>   drivers/gpu/drm/rcar-du/rcar_du_of.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_of.c b/drivers/gpu/drm/rcar-du/rcar_du_of.c
> index afef696..782bfc7 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_of.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_of.c
> @@ -232,7 +232,7 @@ static void __init rcar_du_of_lvds_patch(const struct of_device_id *of_ids)
>   	lvds_node = of_find_compatible_node(NULL, NULL, compatible);
>   	if (lvds_node) {
>   		of_node_put(lvds_node);
> -		return;
> +		goto done;
>   	}
>   


you might have to create multiple level to do handling it.. there are 
unnecessary put being done on "done" which is not valid

for this case.

-Mukesh

>   	/*
Markus Elfring April 8, 2019, 4:38 p.m. UTC | #2
> v2->v1: turn the return into a goto done.

* The version identification can be shorter, can't it?

* The expection handling should be completed for the implementation
  of the function “rcar_du_of_lvds_patch” in a different way.
  https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/rcar-du/rcar_du_of.c?id=ac5b84a1ffe93c9fb882c0f2bdfac1c33077b920#n195

  How do you think about to add a few jump targets (at the end)?

Regards,
Markus

Patch
diff mbox series

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_of.c b/drivers/gpu/drm/rcar-du/rcar_du_of.c
index afef696..782bfc7 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_of.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_of.c
@@ -232,7 +232,7 @@  static void __init rcar_du_of_lvds_patch(const struct of_device_id *of_ids)
 	lvds_node = of_find_compatible_node(NULL, NULL, compatible);
 	if (lvds_node) {
 		of_node_put(lvds_node);
-		return;
+		goto done;
 	}
 
 	/*