UPSTREAM: drm: Do not set connector->encoder in drivers
authorThierry Reding <treding@nvidia.com>
Mon, 16 Nov 2015 17:19:53 +0000 (18:19 +0100)
committerYakir Yang <ykk@rock-chips.com>
Wed, 6 Jul 2016 07:25:34 +0000 (15:25 +0800)
An encoder is associated with a connector by the DRM core as a result of
setting up a configuration. Drivers using the atomic or legacy helpers
should never set up this link, even if it is a static one.

While at it, try to catch this kind of error in the future by adding a
WARN_ON() in drm_mode_connector_attach_encoder(). Note that this doesn't
cover all the cases, since drivers could set this up after attaching.
Drivers that use the atomic helpers will get a warning later on, though,
so hopefully the two combined cover enough to help people avoid this in
the future.

Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Liviu Dudau <Liviu.Dudau@arm.com>
Cc: Mark yao <mark.yao@rock-chips.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1447694393-24700-1-git-send-email-thierry.reding@gmail.com
Change-Id: Iaec2775976574d93810b4e160ac8889d6bb55cad
Signed-off-by: Yakir Yang <ykk@rock-chips.com>
(cherry pick from eb47fe8033d6c2013ce47ec44f39fa0092aa8551)

drivers/gpu/drm/bridge/dw-hdmi.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/i2c/tda998x_drv.c
drivers/gpu/drm/imx/parallel-display.c
drivers/gpu/drm/shmobile/shmob_drm_crtc.c

index 6fbec99e59c2bd1667485417eae397fa0023764f..b0aac4733020e337b5cc0e99a51ac4ab67f15ba3 100644 (file)
@@ -1667,8 +1667,6 @@ static int dw_hdmi_register(struct drm_device *drm, struct dw_hdmi *hdmi)
                                   &dw_hdmi_connector_funcs,
                                   DRM_MODE_CONNECTOR_HDMIA);
 
-       hdmi->connector.encoder = encoder;
-
        drm_mode_connector_attach_encoder(&hdmi->connector, encoder);
 
        return 0;
index 7febc7dc6e68ddd724706a5632296d8b42560848..35af30cedb83237a14187d737716954a264790bb 100644 (file)
@@ -5153,6 +5153,20 @@ int drm_mode_connector_attach_encoder(struct drm_connector *connector,
 {
        int i;
 
+       /*
+        * In the past, drivers have attempted to model the static association
+        * of connector to encoder in simple connector/encoder devices using a
+        * direct assignment of connector->encoder = encoder. This connection
+        * is a logical one and the responsibility of the core, so drivers are
+        * expected not to mess with this.
+        *
+        * Note that the error return should've been enough here, but a large
+        * majority of drivers ignores the return value, so add in a big WARN
+        * to get people's attention.
+        */
+       if (WARN_ON(connector->encoder))
+               return -EINVAL;
+
        for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
                if (connector->encoder_ids[i] == 0) {
                        connector->encoder_ids[i] = encoder->base.id;
index de8c5a023b0ebe8dc86082af296fd43e9fd83764..aefab3dc23e9b27e597134bb8e170c3bdf0b1960 100644 (file)
@@ -1453,7 +1453,6 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)
        if (ret)
                goto err_sysfs;
 
-       priv->connector.encoder = &priv->encoder;
        drm_mode_connector_attach_encoder(&priv->connector, &priv->encoder);
 
        return 0;
index fcbe4d2eeabf40b540cc6dc82917e7cf3e651a94..6a1f4fff8b9c98b2fe31556b9e61a644d060d20f 100644 (file)
@@ -204,8 +204,6 @@ static int imx_pd_register(struct drm_device *drm,
 
        drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder);
 
-       imxpd->connector.encoder = &imxpd->encoder;
-
        return 0;
 }
 
index b80802f551436bb959ee79b08aa003dd16891383..db0763794edcb62de69a9f45c825a0b79b631820 100644 (file)
@@ -739,8 +739,6 @@ int shmob_drm_connector_create(struct shmob_drm_device *sdev,
        if (ret < 0)
                goto err_backlight;
 
-       connector->encoder = encoder;
-
        drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
        drm_object_property_set_value(&connector->base,
                sdev->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);