On Wed, Nov 29, 2017 at 11:45:43AM +0000, Russell King wrote:
> Fix the leak of the CRTC structure in the failure paths of
> armada_drm_crtc_create().
> 
> Signed-off-by: Russell King <rmk+ker...@armlinux.org.uk>
> ---
>  drivers/gpu/drm/armada/armada_crtc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
> b/drivers/gpu/drm/armada/armada_crtc.c
> index 2e065facdce7..844d488b6654 100644
> --- a/drivers/gpu/drm/armada/armada_crtc.c
> +++ b/drivers/gpu/drm/armada/armada_crtc.c
> @@ -1246,11 +1246,14 @@ static int armada_drm_crtc_create(struct drm_device 
> *drm, struct device *dev,
>       dcrtc->crtc.port = port;
>  
>       primary = kzalloc(sizeof(*primary), GFP_KERNEL);
> -     if (!primary)
> +     if (!primary) {
> +             kfree(dcrtc);
>               return -ENOMEM;
> +     }
>  
>       ret = armada_drm_plane_init(primary);
>       if (ret) {
> +             kfree(dcrtc);
>               kfree(primary);
>               return ret;
>       }
> @@ -1262,14 +1265,17 @@ static int armada_drm_crtc_create(struct drm_device 
> *drm, struct device *dev,
>                                      NULL,
>                                      DRM_PLANE_TYPE_PRIMARY, NULL);
>       if (ret) {
> +             kfree(dcrtc);
>               kfree(primary);
>               return ret;
>       }
>  
>       ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, &primary->base, NULL,
>                                       &armada_crtc_funcs, NULL);
> -     if (ret)
> +     if (ret) {
> +             kfree(dcrtc);
>               goto err_crtc_init;

The mixed use of cleaning up at every exit and the lone label is a bit messy and
prone to bugs such as the one you're fixing. How about you label everything
and then just clean up once?

It also seems like you're missing cleanup if armada_overlay_plane_create()
fails?

Sean

> +     }
>  
>       drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
>  
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to