]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm: Validate encoder->possible_crtcs
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 11 Feb 2020 16:22:07 +0000 (18:22 +0200)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 18 Mar 2020 16:38:27 +0000 (18:38 +0200)
WARN if the encoder possible_crtcs is effectively empty or contains
bits for non-existing crtcs.

v2: Move to drm_mode_config_validate() (Daniel)
    Make the docs say we WARN when this is wrong (Daniel)
    Extract full_crtc_mask()

Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200211162208.16224-7-ville.syrjala@linux.intel.com
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/drm_mode_config.c
include/drm/drm_encoder.h

index 4099a626324a7da211b1b646bdd04a5a82ccaa3a..55322d7048f5761b20ed4e7fee96277253e69820 100644 (file)
@@ -581,6 +581,29 @@ static void validate_encoder_possible_clones(struct drm_encoder *encoder)
             encoder->possible_clones, encoder_mask);
 }
 
+static u32 full_crtc_mask(struct drm_device *dev)
+{
+       struct drm_crtc *crtc;
+       u32 crtc_mask = 0;
+
+       drm_for_each_crtc(crtc, dev)
+               crtc_mask |= drm_crtc_mask(crtc);
+
+       return crtc_mask;
+}
+
+static void validate_encoder_possible_crtcs(struct drm_encoder *encoder)
+{
+       u32 crtc_mask = full_crtc_mask(encoder->dev);
+
+       WARN((encoder->possible_crtcs & crtc_mask) == 0 ||
+            (encoder->possible_crtcs & ~crtc_mask) != 0,
+            "Bogus possible_crtcs: "
+            "[ENCODER:%d:%s] possible_crtcs=0x%x (full crtc mask=0x%x)\n",
+            encoder->base.id, encoder->name,
+            encoder->possible_crtcs, crtc_mask);
+}
+
 void drm_mode_config_validate(struct drm_device *dev)
 {
        struct drm_encoder *encoder;
@@ -588,6 +611,8 @@ void drm_mode_config_validate(struct drm_device *dev)
        drm_for_each_encoder(encoder, dev)
                fixup_encoder_possible_clones(encoder);
 
-       drm_for_each_encoder(encoder, dev)
+       drm_for_each_encoder(encoder, dev) {
                validate_encoder_possible_clones(encoder);
+               validate_encoder_possible_crtcs(encoder);
+       }
 }
index 9d11cbe22f3498aa9997565960dfb5bd81eb45cc..a60f5f1555acf9875015951ee371d6db7281690a 100644 (file)
@@ -142,7 +142,7 @@ struct drm_encoder {
         * the bits for all &drm_crtc objects this encoder can be connected to
         * before calling drm_dev_register().
         *
-        * In reality almost every driver gets this wrong.
+        * You will get a WARN if you get this wrong in the driver.
         *
         * Note that since CRTC objects can't be hotplugged the assigned indices
         * are stable and hence known before registering all objects.