drm/fsl-dcu: avoid memory leak on errors
authorStefan Agner <stefan@agner.ch>
Mon, 16 Nov 2015 23:43:34 +0000 (15:43 -0800)
committerStefan Agner <stefan@agner.ch>
Fri, 26 Feb 2016 00:13:16 +0000 (16:13 -0800)
Improve error handling during CRTC initialization. Especially avoid
memory leaks in the primary plane initialization error path.

Signed-off-by: Stefan Agner <stefan@agner.ch>
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c

index f0285c41b29c2633ff0b3df6c034946a9fd70da0..62377e41745bf67191f016983773569b4e8e492a 100644 (file)
@@ -143,10 +143,15 @@ int fsl_dcu_drm_crtc_create(struct fsl_dcu_drm_device *fsl_dev)
        int ret;
 
        primary = fsl_dcu_drm_primary_create_plane(fsl_dev->drm);
+       if (!primary)
+               return -ENOMEM;
+
        ret = drm_crtc_init_with_planes(fsl_dev->drm, crtc, primary, NULL,
                                        &fsl_dcu_drm_crtc_funcs, NULL);
-       if (ret < 0)
+       if (ret) {
+               primary->funcs->destroy(primary);
                return ret;
+       }
 
        drm_crtc_helper_add(crtc, &fsl_dcu_drm_crtc_helper_funcs);
 
index 040ba6bee08d46e5929d00d855f843a123e9a107..1ea70314be1dcea25ebca6652f578fdd8011dd18 100644 (file)
@@ -187,6 +187,7 @@ static const struct drm_plane_helper_funcs fsl_dcu_drm_plane_helper_funcs = {
 static void fsl_dcu_drm_plane_destroy(struct drm_plane *plane)
 {
        drm_plane_cleanup(plane);
+       kfree(plane);
 }
 
 static const struct drm_plane_funcs fsl_dcu_drm_plane_funcs = {