diff mbox series

[v2,6/6] drm: Validate encoder->possible_crtcs

Message ID 20200207135950.6655-7-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm: Try to fix encoder possible_clones/crtc | expand

Commit Message

Ville Syrjälä Feb. 7, 2020, 1:59 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

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?

Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_encoder.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Daniel Vetter Feb. 7, 2020, 4:39 p.m. UTC | #1
On Fri, Feb 07, 2020 at 03:59:50PM +0200, Ville Syrjala wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> 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?
> 
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

From a quick grep it looks like at least most drivers seem to get this
right. Worth a shot to find the hold-outs.

Two things:
- Imo also best to move into the drm_mode_config_validate I suggested.
- Please update the kerneldoc for drm_encoder.possible_crtcs to mention
  that this will WARN if you get it wrong (and maybe remove the line that
  most drivers screw this up).

Check itself lgtm.
-Daniel

> ---
>  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 bc2246f27e0d..f16b2a2518d7 100644
> --- a/drivers/gpu/drm/drm_encoder.c
> +++ b/drivers/gpu/drm/drm_encoder.c
> @@ -107,6 +107,23 @@ static void validate_possible_clones(struct drm_encoder *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;
> @@ -115,6 +132,7 @@ int drm_encoder_register_all(struct drm_device *dev)
>  	fixup_possible_clones(dev);
>  
>  	drm_for_each_encoder(encoder, dev) {
> +		validate_possible_crtcs(encoder);
>  		validate_possible_clones(encoder);
>  
>  		if (encoder->funcs->late_register)
> -- 
> 2.24.1
>
Ville Syrjälä Feb. 7, 2020, 4:49 p.m. UTC | #2
On Fri, Feb 07, 2020 at 05:39:26PM +0100, Daniel Vetter wrote:
> On Fri, Feb 07, 2020 at 03:59:50PM +0200, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > 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?
> > 
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> >From a quick grep it looks like at least most drivers seem to get this
> right. Worth a shot to find the hold-outs.
> 
> Two things:
> - Imo also best to move into the drm_mode_config_validate I suggested.
> - Please update the kerneldoc for drm_encoder.possible_crtcs to mention
>   that this will WARN if you get it wrong (and maybe remove the line that
>   most drivers screw this up).

ack

> 
> Check itself lgtm.
> -Daniel
> 
> > ---
> >  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 bc2246f27e0d..f16b2a2518d7 100644
> > --- a/drivers/gpu/drm/drm_encoder.c
> > +++ b/drivers/gpu/drm/drm_encoder.c
> > @@ -107,6 +107,23 @@ static void validate_possible_clones(struct drm_encoder *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;
> > @@ -115,6 +132,7 @@ int drm_encoder_register_all(struct drm_device *dev)
> >  	fixup_possible_clones(dev);
> >  
> >  	drm_for_each_encoder(encoder, dev) {
> > +		validate_possible_crtcs(encoder);
> >  		validate_possible_clones(encoder);
> >  
> >  		if (encoder->funcs->late_register)
> > -- 
> > 2.24.1
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index bc2246f27e0d..f16b2a2518d7 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -107,6 +107,23 @@  static void validate_possible_clones(struct drm_encoder *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;
@@ -115,6 +132,7 @@  int drm_encoder_register_all(struct drm_device *dev)
 	fixup_possible_clones(dev);
 
 	drm_for_each_encoder(encoder, dev) {
+		validate_possible_crtcs(encoder);
 		validate_possible_clones(encoder);
 
 		if (encoder->funcs->late_register)