drm/vkms: init plane using drmm_universal_plane_alloc
authorMelissa Wen <melissa.srw@gmail.com>
Sat, 24 Apr 2021 08:23:27 +0000 (05:23 -0300)
committerMelissa Wen <melissa.srw@gmail.com>
Thu, 29 Apr 2021 21:44:43 +0000 (18:44 -0300)
By using drmm_universal_plane_alloc instead of
drm_universal_plane_init, we let the DRM infrastructure handles
resource allocation and cleanup. We can also get rid of some
code repetitions for plane cleanup, improving code maintainability
in vkms.

Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/3bbdabed0274d2d0917d1b829dd16f13d7b495f5.1619250933.git.melissa.srw@gmail.com
drivers/gpu/drm/vkms/vkms_drv.h
drivers/gpu/drm/vkms/vkms_output.c
drivers/gpu/drm/vkms/vkms_plane.c

index 35540c7c4416925695bb7cbda716a2598bec28c3..70fb7962161760bad2e714b1c37175dc5493290f 100644 (file)
@@ -37,6 +37,10 @@ struct vkms_plane_state {
        struct vkms_composer *composer;
 };
 
+struct vkms_plane {
+       struct drm_plane base;
+};
+
 /**
  * vkms_crtc_state - Driver specific CRTC state
  * @base: base CRTC state
@@ -114,8 +118,8 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 
 int vkms_output_init(struct vkms_device *vkmsdev, int index);
 
-struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-                                 enum drm_plane_type type, int index);
+struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
+                                  enum drm_plane_type type, int index);
 
 /* CRC Support */
 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
index f5f6f15c362c0011b4f0bbc32314c177f4e378ef..6979fbc7f82127e0d2da296c2925168a97aec8ed 100644 (file)
@@ -39,7 +39,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
        struct drm_connector *connector = &output->connector;
        struct drm_encoder *encoder = &output->encoder;
        struct drm_crtc *crtc = &output->crtc;
-       struct drm_plane *primary, *cursor = NULL;
+       struct vkms_plane *primary, *cursor = NULL;
        int ret;
        int writeback;
 
@@ -49,15 +49,13 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 
        if (vkmsdev->config->cursor) {
                cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
-               if (IS_ERR(cursor)) {
-                       ret = PTR_ERR(cursor);
-                       goto err_cursor;
-               }
+               if (IS_ERR(cursor))
+                       return PTR_ERR(cursor);
        }
 
-       ret = vkms_crtc_init(dev, crtc, primary, cursor);
+       ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
        if (ret)
-               goto err_crtc;
+               return ret;
 
        ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
                                 DRM_MODE_CONNECTOR_VIRTUAL);
@@ -100,12 +98,5 @@ err_encoder:
 err_connector:
        drm_crtc_cleanup(crtc);
 
-err_crtc:
-       if (vkmsdev->config->cursor)
-               drm_plane_cleanup(cursor);
-
-err_cursor:
-       drm_plane_cleanup(primary);
-
        return ret;
 }
index 6d310d31b75d4ccb542ed6bed17645fa7284365b..135140f8e87a9423f58ebed10cec39167fd8da72 100644 (file)
@@ -86,7 +86,6 @@ static void vkms_plane_reset(struct drm_plane *plane)
 static const struct drm_plane_funcs vkms_plane_funcs = {
        .update_plane           = drm_atomic_helper_update_plane,
        .disable_plane          = drm_atomic_helper_disable_plane,
-       .destroy                = drm_plane_cleanup,
        .reset                  = vkms_plane_reset,
        .atomic_duplicate_state = vkms_plane_duplicate_state,
        .atomic_destroy_state   = vkms_plane_destroy_state,
@@ -191,18 +190,14 @@ static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = {
        .cleanup_fb             = vkms_cleanup_fb,
 };
 
-struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-                                 enum drm_plane_type type, int index)
+struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
+                                  enum drm_plane_type type, int index)
 {
        struct drm_device *dev = &vkmsdev->drm;
        const struct drm_plane_helper_funcs *funcs;
-       struct drm_plane *plane;
+       struct vkms_plane *plane;
        const u32 *formats;
-       int ret, nformats;
-
-       plane = kzalloc(sizeof(*plane), GFP_KERNEL);
-       if (!plane)
-               return ERR_PTR(-ENOMEM);
+       int nformats;
 
        if (type == DRM_PLANE_TYPE_CURSOR) {
                formats = vkms_cursor_formats;
@@ -214,16 +209,14 @@ struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
                funcs = &vkms_primary_helper_funcs;
        }
 
-       ret = drm_universal_plane_init(dev, plane, 1 << index,
-                                      &vkms_plane_funcs,
-                                      formats, nformats,
-                                      NULL, type, NULL);
-       if (ret) {
-               kfree(plane);
-               return ERR_PTR(ret);
-       }
+       plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index,
+                                          &vkms_plane_funcs,
+                                          formats, nformats,
+                                          NULL, type, NULL);
+       if (IS_ERR(plane))
+               return plane;
 
-       drm_plane_helper_add(plane, funcs);
+       drm_plane_helper_add(&plane->base, funcs);
 
        return plane;
 }