diff mbox series

drm: rcar-du: Fix memory leak in rcar_du_vsps_init()

Message ID 20231115150932.107796-1-biju.das.jz@bp.renesas.com (mailing list archive)
State New, archived
Headers show
Series drm: rcar-du: Fix memory leak in rcar_du_vsps_init() | expand

Commit Message

Biju Das Nov. 15, 2023, 3:09 p.m. UTC
The rcar_du_vsps_init() doesn't free the np allocated by
of_parse_phandle_with_fixed_args() for the non-error case.

Fix memory leak for the non-error case.

Fixes: 3e81374e2014 ("drm: rcar-du: Support multiple sources from the same VSP")
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Laurent Pinchart Nov. 16, 2023, 1:24 a.m. UTC | #1
Hi Biju,

Thank you for the patch.

On Wed, Nov 15, 2023 at 03:09:32PM +0000, Biju Das wrote:
> The rcar_du_vsps_init() doesn't free the np allocated by
> of_parse_phandle_with_fixed_args() for the non-error case.
> 
> Fix memory leak for the non-error case.

Good catch.

> Fixes: 3e81374e2014 ("drm: rcar-du: Support multiple sources from the same VSP")
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
>  drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> index 70d8ad065bfa..5cd54ea33313 100644
> --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> @@ -747,8 +747,6 @@ static int rcar_du_vsps_init(struct rcar_du_device *rcdu)
>  			goto error;
>  	}
>  
> -	return 0;
> -
>  error:

If the code path is used in non-error cases as well, I'd prefer renaming
it to "done".

>  	for (i = 0; i < ARRAY_SIZE(vsps); ++i)
>  		of_node_put(vsps[i].np);

The next line is

	return ret;

When reached in the non-error case, ret is guaranteed to be
non-negative, as it has been assigned to the return value of
rcar_du_vsp_init(), with an

	if (ret < 0)

error check following it. While rcar_du_vsp_init() doesn't return a
positive value today, the code here would break in a way that may not be
immediately visible during review if this changed. I thus recommend
either assigning

	ret = 0;

in the success case, just before the "done" label, or changing the

	if (ret < 0)

test with

	if (ret)

after the call to rcar_du_vsp_init(). I think I have a preference for
the latter.
Biju Das Nov. 16, 2023, 11:19 a.m. UTC | #2
Hi Laurent,

Thanks for the feedback.

> -----Original Message-----
> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Sent: Thursday, November 16, 2023 1:25 AM
> Subject: Re: [PATCH] drm: rcar-du: Fix memory leak in rcar_du_vsps_init()
> 
> Hi Biju,
> 
> Thank you for the patch.
> 
> On Wed, Nov 15, 2023 at 03:09:32PM +0000, Biju Das wrote:
> > The rcar_du_vsps_init() doesn't free the np allocated by
> > of_parse_phandle_with_fixed_args() for the non-error case.
> >
> > Fix memory leak for the non-error case.
> 
> Good catch.
> 
> > Fixes: 3e81374e2014 ("drm: rcar-du: Support multiple sources from the
> > same VSP")
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > ---
> >  drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> > b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> > index 70d8ad065bfa..5cd54ea33313 100644
> > --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> > +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
> > @@ -747,8 +747,6 @@ static int rcar_du_vsps_init(struct rcar_du_device
> *rcdu)
> >  			goto error;
> >  	}
> >
> > -	return 0;
> > -
> >  error:
> 
> If the code path is used in non-error cases as well, I'd prefer renaming
> it to "done".
> 
> >  	for (i = 0; i < ARRAY_SIZE(vsps); ++i)
> >  		of_node_put(vsps[i].np);
> 
> The next line is
> 
> 	return ret;
> 
> When reached in the non-error case, ret is guaranteed to be non-negative,
> as it has been assigned to the return value of rcar_du_vsp_init(), with an
> 
> 	if (ret < 0)
> 
> error check following it. While rcar_du_vsp_init() doesn't return a
> positive value today, the code here would break in a way that may not be
> immediately visible during review if this changed. I thus recommend either
> assigning
> 
> 	ret = 0;
> 
> in the success case, just before the "done" label, or changing the
> 
> 	if (ret < 0)
> 
> test with
> 
> 	if (ret)
> 
> after the call to rcar_du_vsp_init(). I think I have a preference for the
> latter.

Agreed, will send v2 for changing error->done and if (ret) condition.

Cheers,
Biju
diff mbox series

Patch

diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
index 70d8ad065bfa..5cd54ea33313 100644
--- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
+++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c
@@ -747,8 +747,6 @@  static int rcar_du_vsps_init(struct rcar_du_device *rcdu)
 			goto error;
 	}
 
-	return 0;
-
 error:
 	for (i = 0; i < ARRAY_SIZE(vsps); ++i)
 		of_node_put(vsps[i].np);