diff mbox

[v3,3/6] drm/i915: Check encoder type in enc_to_dig_port()

Message ID 20170222063431.10060-4-ander.conselvan.de.oliveira@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ander Conselvan de Oliveira Feb. 22, 2017, 6:34 a.m. UTC
Don't allow conversion from arbitraty encoder types to a digital port.
Calling enc_to_dig_port() with the wrong encoder may seem far fetched,
but certain paths of the ddi code may be called with hasell's analog
encoder and the conversion is wrong for DP mst encoders too, so safe
guard against it.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Imre Deak Feb. 24, 2017, 1:38 p.m. UTC | #1
On Wed, Feb 22, 2017 at 08:34:28AM +0200, Ander Conselvan de Oliveira wrote:
> Don't allow conversion from arbitraty encoder types to a digital port.
> Calling enc_to_dig_port() with the wrong encoder may seem far fetched,
> but certain paths of the ddi code may be called with hasell's analog
> encoder and the conversion is wrong for DP mst encoders too, so safe
> guard against it.
> 
> Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_drv.h | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index a3cf866..2011651 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1121,7 +1121,18 @@ intel_attached_encoder(struct drm_connector *connector)
>  static inline struct intel_digital_port *
>  enc_to_dig_port(struct drm_encoder *encoder)
>  {
> -	return container_of(encoder, struct intel_digital_port, base.base);
> +	struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
> +
> +	switch (intel_encoder->type) {
> +	case INTEL_OUTPUT_DP:
> +	case INTEL_OUTPUT_EDP:
> +	case INTEL_OUTPUT_HDMI:
> +	case INTEL_OUTPUT_UNKNOWN:

Nitpick: for UNKNOWN could've added a WARN_ON(!DDI) check. Either way:
Reviewed-by: Imre Deak <imre.deak@intel.com>

> +		return container_of(encoder, struct intel_digital_port,
> +				    base.base);
> +	default:
> +		return NULL;
> +	}
>  }
>  
>  static inline struct intel_dp_mst_encoder *
> -- 
> 2.9.3
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index a3cf866..2011651 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1121,7 +1121,18 @@  intel_attached_encoder(struct drm_connector *connector)
 static inline struct intel_digital_port *
 enc_to_dig_port(struct drm_encoder *encoder)
 {
-	return container_of(encoder, struct intel_digital_port, base.base);
+	struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
+
+	switch (intel_encoder->type) {
+	case INTEL_OUTPUT_DP:
+	case INTEL_OUTPUT_EDP:
+	case INTEL_OUTPUT_HDMI:
+	case INTEL_OUTPUT_UNKNOWN:
+		return container_of(encoder, struct intel_digital_port,
+				    base.base);
+	default:
+		return NULL;
+	}
 }
 
 static inline struct intel_dp_mst_encoder *