drm/vc4: hdmi: Switch to DRM-managed connector initialization
authorMaxime Ripard <maxime@cerno.tech>
Mon, 11 Jul 2022 17:39:10 +0000 (19:39 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 13 Jul 2022 08:46:10 +0000 (10:46 +0200)
The current code will call drm_connector_unregister() and
drm_connector_cleanup() when the device is unbound. However, by then, there
might still be some references held to that connector, 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>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220711173939.1132294-41-maxime@cerno.tech
drivers/gpu/drm/vc4/vc4_hdmi.c

index 6c44faea4af1b1e1c2c5dc353d924fa9c6045143..283fea78f3cf9029a3e9ef2bf013a2719fd73d9c 100644 (file)
@@ -374,7 +374,6 @@ vc4_hdmi_connector_duplicate_state(struct drm_connector *connector)
 static const struct drm_connector_funcs vc4_hdmi_connector_funcs = {
        .detect = vc4_hdmi_connector_detect,
        .fill_modes = drm_helper_probe_single_connector_modes,
-       .destroy = drm_connector_cleanup,
        .reset = vc4_hdmi_connector_reset,
        .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state,
        .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
@@ -392,10 +391,13 @@ static int vc4_hdmi_connector_init(struct drm_device *dev,
        struct drm_encoder *encoder = &vc4_hdmi->encoder.base;
        int ret;
 
-       drm_connector_init_with_ddc(dev, connector,
-                                   &vc4_hdmi_connector_funcs,
-                                   DRM_MODE_CONNECTOR_HDMIA,
-                                   vc4_hdmi->ddc);
+       ret = drmm_connector_init(dev, connector,
+                                 &vc4_hdmi_connector_funcs,
+                                 DRM_MODE_CONNECTOR_HDMIA,
+                                 vc4_hdmi->ddc);
+       if (ret)
+               return ret;
+
        drm_connector_helper_add(connector, &vc4_hdmi_connector_helper_funcs);
 
        /*
@@ -2999,7 +3001,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 
        ret = vc4_hdmi_hotplug_init(vc4_hdmi);
        if (ret)
-               goto err_destroy_conn;
+               goto err_put_runtime_pm;
 
        ret = vc4_hdmi_cec_init(vc4_hdmi);
        if (ret)
@@ -3021,8 +3023,6 @@ err_free_cec:
        vc4_hdmi_cec_exit(vc4_hdmi);
 err_free_hotplug:
        vc4_hdmi_hotplug_exit(vc4_hdmi);
-err_destroy_conn:
-       drm_connector_cleanup(&vc4_hdmi->connector);
 err_put_runtime_pm:
        pm_runtime_put_sync(dev);
 err_disable_runtime_pm:
@@ -3065,7 +3065,6 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
        vc4_hdmi_audio_exit(vc4_hdmi);
        vc4_hdmi_cec_exit(vc4_hdmi);
        vc4_hdmi_hotplug_exit(vc4_hdmi);
-       drm_connector_cleanup(&vc4_hdmi->connector);
 
        pm_runtime_disable(dev);