diff mbox series

[v2,5/5] drm/i915/ddi: only call shutdown hooks for valid encoders

Message ID c2c5a2b276064842c1493a7efb9e6bd3159e2a98.1733324735.git.jani.nikula@intel.com (mailing list archive)
State New
Headers show
Series drm/i915/display: handle hdmi connector init failures, and no HDMI/DP cases | expand

Commit Message

Jani Nikula Dec. 4, 2024, 3:07 p.m. UTC
DDI might be HDMI or DP only, leaving the other encoder
uninitialized. Calling the shutdown hook on an uninitialized encoder may
lead to a NULL pointer dereference. Check the encoder types (and thus
validity via the DP output_reg or HDMI hdmi_reg checks) before calling
the hooks.

Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Closes: https://lore.kernel.org/r/20241031105145.2140590-1-senozhatsky@chromium.org
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

---

TODO: We should probably audit all DDI encoder hooks for this, and add
the necessary checks.
---
 drivers/gpu/drm/i915/display/intel_ddi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Suraj Kandpal Dec. 5, 2024, 3:52 a.m. UTC | #1
> -----Original Message-----
> From: Intel-xe <intel-xe-bounces@lists.freedesktop.org> On Behalf Of Jani
> Nikula
> Sent: Wednesday, December 4, 2024 8:37 PM
> To: intel-gfx@lists.freedesktop.org; intel-xe@lists.freedesktop.org
> Cc: Nikula, Jani <jani.nikula@intel.com>; Sergey Senozhatsky
> <senozhatsky@chromium.org>; Ville Syrjala <ville.syrjala@linux.intel.com>
> Subject: [PATCH v2 5/5] drm/i915/ddi: only call shutdown hooks for valid
> encoders
> 
> DDI might be HDMI or DP only, leaving the other encoder uninitialized. Calling
> the shutdown hook on an uninitialized encoder may lead to a NULL pointer
> dereference. Check the encoder types (and thus validity via the DP output_reg
> or HDMI hdmi_reg checks) before calling the hooks.
> 
> Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Closes: https://lore.kernel.org/r/20241031105145.2140590-1-
> senozhatsky@chromium.org
> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
> Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

LGTM,
Reviewed-by: Suraj Kandpal <suraj.kandpal@intel.com>

> 
> ---
> 
> TODO: We should probably audit all DDI encoder hooks for this, and add the
> necessary checks.
> ---
>  drivers/gpu/drm/i915/display/intel_ddi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c
> b/drivers/gpu/drm/i915/display/intel_ddi.c
> index 67bbfba58b54..f3e27c67c419 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> @@ -4920,8 +4920,10 @@ static void
> intel_ddi_tc_encoder_suspend_complete(struct intel_encoder *encoder)
> 
>  static void intel_ddi_encoder_shutdown(struct intel_encoder *encoder)  {
> -	intel_dp_encoder_shutdown(encoder);
> -	intel_hdmi_encoder_shutdown(encoder);
> +	if (intel_encoder_is_dp(encoder))
> +		intel_dp_encoder_shutdown(encoder);
> +	if (intel_encoder_is_hdmi(encoder))
> +		intel_hdmi_encoder_shutdown(encoder);
>  }
> 
>  static void intel_ddi_tc_encoder_shutdown_complete(struct intel_encoder
> *encoder)
> --
> 2.39.5
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
index 67bbfba58b54..f3e27c67c419 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -4920,8 +4920,10 @@  static void intel_ddi_tc_encoder_suspend_complete(struct intel_encoder *encoder)
 
 static void intel_ddi_encoder_shutdown(struct intel_encoder *encoder)
 {
-	intel_dp_encoder_shutdown(encoder);
-	intel_hdmi_encoder_shutdown(encoder);
+	if (intel_encoder_is_dp(encoder))
+		intel_dp_encoder_shutdown(encoder);
+	if (intel_encoder_is_hdmi(encoder))
+		intel_hdmi_encoder_shutdown(encoder);
 }
 
 static void intel_ddi_tc_encoder_shutdown_complete(struct intel_encoder *encoder)