Skip to content

Commit 74d2aac

Browse files
committed
drm: Validate encoder->possible_clones
Many drivers are populating encoder->possible_clones wrong. Let's persuade them to get it right by adding some loud WARNs. We'll cross check the bits between any two encoders. So either both encoders can clone with the other, or neither can. We'll also complain about effectively empty possible_clones, and possible_clones containing bits for encoders that don't exist. v2: encoder->possible_clones now includes the encoder itelf v3: Move to drm_mode_config_validate() (Daniel) Document that you get a WARN when this is wrong (Daniel) Extract full_encoder_mask() v4: !! instead of ! (Daniel) Acked-by: 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-6-ville.syrjala@linux.intel.com Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 9cb6a97 commit 74d2aac

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/gpu/drm/drm_mode_config.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,17 @@ void drm_mode_config_cleanup(struct drm_device *dev)
533533
}
534534
EXPORT_SYMBOL(drm_mode_config_cleanup);
535535

536+
static u32 full_encoder_mask(struct drm_device *dev)
537+
{
538+
struct drm_encoder *encoder;
539+
u32 encoder_mask = 0;
540+
541+
drm_for_each_encoder(encoder, dev)
542+
encoder_mask |= drm_encoder_mask(encoder);
543+
544+
return encoder_mask;
545+
}
546+
536547
/*
537548
* For some reason we want the encoder itself included in
538549
* possible_clones. Make life easy for drivers by allowing them
@@ -544,10 +555,39 @@ static void fixup_encoder_possible_clones(struct drm_encoder *encoder)
544555
encoder->possible_clones = drm_encoder_mask(encoder);
545556
}
546557

558+
static void validate_encoder_possible_clones(struct drm_encoder *encoder)
559+
{
560+
struct drm_device *dev = encoder->dev;
561+
u32 encoder_mask = full_encoder_mask(dev);
562+
struct drm_encoder *other;
563+
564+
drm_for_each_encoder(other, dev) {
565+
WARN(!!(encoder->possible_clones & drm_encoder_mask(other)) !=
566+
!!(other->possible_clones & drm_encoder_mask(encoder)),
567+
"possible_clones mismatch: "
568+
"[ENCODER:%d:%s] mask=0x%x possible_clones=0x%x vs. "
569+
"[ENCODER:%d:%s] mask=0x%x possible_clones=0x%x\n",
570+
encoder->base.id, encoder->name,
571+
drm_encoder_mask(encoder), encoder->possible_clones,
572+
other->base.id, other->name,
573+
drm_encoder_mask(other), other->possible_clones);
574+
}
575+
576+
WARN((encoder->possible_clones & drm_encoder_mask(encoder)) == 0 ||
577+
(encoder->possible_clones & ~encoder_mask) != 0,
578+
"Bogus possible_clones: "
579+
"[ENCODER:%d:%s] possible_clones=0x%x (full encoder mask=0x%x)\n",
580+
encoder->base.id, encoder->name,
581+
encoder->possible_clones, encoder_mask);
582+
}
583+
547584
void drm_mode_config_validate(struct drm_device *dev)
548585
{
549586
struct drm_encoder *encoder;
550587

551588
drm_for_each_encoder(encoder, dev)
552589
fixup_encoder_possible_clones(encoder);
590+
591+
drm_for_each_encoder(encoder, dev)
592+
validate_encoder_possible_clones(encoder);
553593
}

include/drm/drm_encoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ struct drm_encoder {
163163
* any cloning it can leave @possible_clones set to 0. The core will
164164
* automagically fix this up by setting the bit for the encoder itself.
165165
*
166+
* You will get a WARN if you get this wrong in the driver.
167+
*
166168
* Note that since encoder objects can't be hotplugged the assigned indices
167169
* are stable and hence known before registering all objects.
168170
*/

0 commit comments

Comments
 (0)