diff mbox series

[v2] drm/i915/debugfs: HDCP capability enc NULL check

Message ID 20210211062949.7045-1-anshuman.gupta@intel.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/i915/debugfs: HDCP capability enc NULL check | expand

Commit Message

Anshuman Gupta Feb. 11, 2021, 6:29 a.m. UTC
DP-MST connector encoder initializes at modeset
Adding a connector->encoder NULL check in order to
avoid any NULL pointer dereference.
intel_hdcp_enable() already handle this but debugfs
can also invoke the intel_{hdcp,hdcp2_capable}.
Handling it gracefully.

v2:
- Use necessary lock and NULL check in
  i915_hdcp_sink_capability_show. [Imre]

Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
---
 .../gpu/drm/i915/display/intel_display_debugfs.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Imre Deak Feb. 11, 2021, 11:48 a.m. UTC | #1
On Thu, Feb 11, 2021 at 11:59:49AM +0530, Anshuman Gupta wrote:
> DP-MST connector encoder initializes at modeset
> Adding a connector->encoder NULL check in order to
> avoid any NULL pointer dereference.
> intel_hdcp_enable() already handle this but debugfs
> can also invoke the intel_{hdcp,hdcp2_capable}.
> Handling it gracefully.
> 
> v2:
> - Use necessary lock and NULL check in
>   i915_hdcp_sink_capability_show. [Imre]
> 
> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> ---
>  .../gpu/drm/i915/display/intel_display_debugfs.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
> index d6e4a9237bda..ed5e2f65b171 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
> +++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
> @@ -2198,14 +2198,26 @@ DEFINE_SHOW_ATTRIBUTE(i915_panel);
>  static int i915_hdcp_sink_capability_show(struct seq_file *m, void *data)
>  {
>  	struct drm_connector *connector = m->private;
> +	struct drm_i915_private *i915 = to_i915(connector->dev);
>  	struct intel_connector *intel_connector = to_intel_connector(connector);
> +	int ret;
>  
> -	if (connector->status != connector_status_connected)
> -		return -ENODEV;
> +	ret = drm_modeset_lock_single_interruptible(&i915->drm.mode_config.connection_mutex);
> +	if (ret)
> +		return ret;
> +
> +	if (!connector->encoder || connector->status != connector_status_connected) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
>  
>  	seq_printf(m, "%s:%d HDCP version: ", connector->name,
>  		   connector->base.id);
>  	intel_hdcp_info(m, intel_connector);
> +out:
> +	drm_modeset_unlock(&i915->drm.mode_config.connection_mutex);
> +	if (ret)
> +		return ret;
>  
>  	return 0;

Could be just
	return ret;

Reviewed-by: Imre Deak <imre.deak@intel.com>

>  }
> -- 
> 2.26.2
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index d6e4a9237bda..ed5e2f65b171 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -2198,14 +2198,26 @@  DEFINE_SHOW_ATTRIBUTE(i915_panel);
 static int i915_hdcp_sink_capability_show(struct seq_file *m, void *data)
 {
 	struct drm_connector *connector = m->private;
+	struct drm_i915_private *i915 = to_i915(connector->dev);
 	struct intel_connector *intel_connector = to_intel_connector(connector);
+	int ret;
 
-	if (connector->status != connector_status_connected)
-		return -ENODEV;
+	ret = drm_modeset_lock_single_interruptible(&i915->drm.mode_config.connection_mutex);
+	if (ret)
+		return ret;
+
+	if (!connector->encoder || connector->status != connector_status_connected) {
+		ret = -ENODEV;
+		goto out;
+	}
 
 	seq_printf(m, "%s:%d HDCP version: ", connector->name,
 		   connector->base.id);
 	intel_hdcp_info(m, intel_connector);
+out:
+	drm_modeset_unlock(&i915->drm.mode_config.connection_mutex);
+	if (ret)
+		return ret;
 
 	return 0;
 }