drm/vc4: crtc: Switch to DRM-managed CRTC initialization
authorMaxime Ripard <maxime@cerno.tech>
Mon, 11 Jul 2022 17:38:52 +0000 (19:38 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 13 Jul 2022 08:46:07 +0000 (10:46 +0200)
The current code will call drm_crtc_cleanup() when the device is
unbound. However, by then, there might still be some references held to
that CRTC, including by the userspace that might still have the DRM
device open.

Let's switch to a DRM-managed initialization to clean up after ourselves
only once the DRM device has been last closed.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220711173939.1132294-23-maxime@cerno.tech
drivers/gpu/drm/vc4/vc4_crtc.c
drivers/gpu/drm/vc4/vc4_drv.h
drivers/gpu/drm/vc4/vc4_txp.c

index d5158a6..3768a2a 100644 (file)
@@ -206,11 +206,6 @@ static bool vc4_crtc_get_scanout_position(struct drm_crtc *crtc,
        return ret;
 }
 
-void vc4_crtc_destroy(struct drm_crtc *crtc)
-{
-       drm_crtc_cleanup(crtc);
-}
-
 static u32 vc4_get_fifo_full_level(struct vc4_crtc *vc4_crtc, u32 format)
 {
        const struct vc4_crtc_data *crtc_data = vc4_crtc_to_vc4_crtc_data(vc4_crtc);
@@ -1059,7 +1054,6 @@ void vc4_crtc_reset(struct drm_crtc *crtc)
 
 static const struct drm_crtc_funcs vc4_crtc_funcs = {
        .set_config = drm_atomic_helper_set_config,
-       .destroy = vc4_crtc_destroy,
        .page_flip = vc4_page_flip,
        .set_property = NULL,
        .cursor_set = NULL, /* handled by drm_mode_cursor_universal */
@@ -1237,6 +1231,7 @@ int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
        struct drm_crtc *crtc = &vc4_crtc->base;
        struct drm_plane *primary_plane;
        unsigned int i;
+       int ret;
 
        /* For now, we create just the primary and the legacy cursor
         * planes.  We should be able to stack more planes on easily,
@@ -1251,8 +1246,11 @@ int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
        }
 
        spin_lock_init(&vc4_crtc->irq_lock);
-       drm_crtc_init_with_planes(drm, crtc, primary_plane, NULL,
-                                 crtc_funcs, NULL);
+       ret = drmm_crtc_init_with_planes(drm, crtc, primary_plane, NULL,
+                                        crtc_funcs, NULL);
+       if (ret)
+               return ret;
+
        drm_crtc_helper_add(crtc, crtc_helper_funcs);
 
        if (!vc4->is_vc5) {
@@ -1332,8 +1330,6 @@ static void vc4_crtc_unbind(struct device *dev, struct device *master,
        struct platform_device *pdev = to_platform_device(dev);
        struct vc4_crtc *vc4_crtc = dev_get_drvdata(dev);
 
-       vc4_crtc_destroy(&vc4_crtc->base);
-
        CRTC_WRITE(PV_INTEN, 0);
 
        platform_set_drvdata(pdev, NULL);
index 443894e..116e54f 100644 (file)
@@ -851,7 +851,6 @@ int vc4_crtc_disable_at_boot(struct drm_crtc *crtc);
 int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
                  const struct drm_crtc_funcs *crtc_funcs,
                  const struct drm_crtc_helper_funcs *crtc_helper_funcs);
-void vc4_crtc_destroy(struct drm_crtc *crtc);
 int vc4_page_flip(struct drm_crtc *crtc,
                  struct drm_framebuffer *fb,
                  struct drm_pending_vblank_event *event,
index 20e08e3..448d48e 100644 (file)
@@ -384,7 +384,6 @@ static void vc4_txp_disable_vblank(struct drm_crtc *crtc) {}
 
 static const struct drm_crtc_funcs vc4_txp_crtc_funcs = {
        .set_config             = drm_atomic_helper_set_config,
-       .destroy                = vc4_crtc_destroy,
        .page_flip              = vc4_page_flip,
        .reset                  = vc4_crtc_reset,
        .atomic_duplicate_state = vc4_crtc_duplicate_state,