[PATCH 14/14] drm: Validate encoder->possible_crtcs

Ville Syrjala
2018-06-15T16:49:25Z

WARN if the encoder possible_crtcs is effectively empty or contains
bits for non-existing crtcs.

TODO: Or should we perhapst just filter out any bit for a
non-exisiting crtc?

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
drivers/gpu/drm/drm_encoder.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index 1c289b227bbc..cfe6e719ee2b 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -107,12 +107,30 @@ static void validate_possible_clones(struct drm_encoder *encoder)
possible_clones, encoder_mask);
}

+static void validate_possible_crtcs(struct drm_encoder *encoder)
+{
+ struct drm_device *dev = encoder->dev;
+ struct drm_crtc *crtc;
+ u32 crtc_mask = 0;
+
+ drm_for_each_crtc(crtc, dev)
+ crtc_mask |= drm_crtc_mask(crtc);
+
+ 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);
+}
+
int drm_encoder_register_all(struct drm_device *dev)
{
struct drm_encoder *encoder;
int ret = 0;

drm_for_each_encoder(encoder, dev) {
+ validate_possible_crtcs(encoder);
validate_possible_clones(encoder);

if (encoder->funcs->late_register)