Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Ankit Nautiyal <ankit.k.nautiyal@intel.com>,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Subject: Re: [PATCH] drm/i915/hdmi: Fix potential overflow while using intel_encoder_to_tc
Date: Wed, 03 Sep 2025 10:37:07 +0300	[thread overview]
Message-ID: <29e10fcd0e9bf9e995739cf53ae8f49544ebb06a@intel.com> (raw)
In-Reply-To: <20250903035022.3654997-1-ankit.k.nautiyal@intel.com>

On Wed, 03 Sep 2025, Ankit Nautiyal <ankit.k.nautiyal@intel.com> wrote:
> The helper intel_encoder_to_tc() can potentially return TC_PORT_NONE
> (-1) and cause overflow while computing ddc pins in
> icl_encoder_to_ddc_pin().
>
> Check for TC_PORT_NONE before deriving the ddc pins for TC port.
>
> Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_hdmi.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_hdmi.c b/drivers/gpu/drm/i915/display/intel_hdmi.c
> index cbee628eb26b..85f70cedc40c 100644
> --- a/drivers/gpu/drm/i915/display/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/display/intel_hdmi.c
> @@ -2791,10 +2791,16 @@ static u8 icl_encoder_to_ddc_pin(struct intel_encoder *encoder)
>  	struct intel_display *display = to_intel_display(encoder);
>  	enum port port = encoder->port;
>  
> -	if (intel_encoder_is_combo(encoder))
> +	if (intel_encoder_is_combo(encoder)) {
>  		return GMBUS_PIN_1_BXT + port;
> -	else if (intel_encoder_is_tc(encoder))
> -		return GMBUS_PIN_9_TC1_ICP + intel_encoder_to_tc(encoder);
> +	} else if (intel_encoder_is_tc(encoder)) {
> +		enum tc_port tc_port = intel_encoder_to_tc(encoder);

intel_encoder_to_tc() can only return TC_PORT_NONE if intel_phy_is_tc()
== false. But intel_encoder_is_tc() just above means intel_phy_is_tc()
== true.

This case can't happen, it's a static analyzer being overzealous.

Adding checks like this to please a static analyzer leads to misery,
because it adds unnecessary code to maintain, and it will never be run.

I think it would be more interesting to make intel_port_to_tc() WARN on
!intel_phy_is_tc(), return a bogus >= 0 port, and ensure all callers
only call it on TC ports.

This obviously leads to issues if it happens, but hey, it shouldn't
happen, and intel_encoder_to_tc() returning TC_PORT_NONE is *already*
such a case. Just move it to lower levels.

If we start checking for every impossible situation, and propagating
errors for them, our codebase will be 90% error handling.


BR,
Jani.


> +
> +		if (tc_port != TC_PORT_NONE)
> +			return GMBUS_PIN_9_TC1_ICP + tc_port;
> +
> +		drm_WARN(display->drm, 1, "Invalid TC port\n");
> +	}
>  
>  	drm_WARN(display->drm, 1, "Unknown port:%c\n", port_name(port));
>  	return GMBUS_PIN_2_BXT;

-- 
Jani Nikula, Intel

  parent reply	other threads:[~2025-09-03  7:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03  3:50 [PATCH] drm/i915/hdmi: Fix potential overflow while using intel_encoder_to_tc Ankit Nautiyal
2025-09-03  4:41 ` ✓ CI.KUnit: success for " Patchwork
2025-09-03  5:22 ` ✓ Xe.CI.BAT: " Patchwork
2025-09-03  7:37 ` Jani Nikula [this message]
2025-09-03  9:57   ` [PATCH] " Nautiyal, Ankit K
2025-09-03 10:16     ` Jani Nikula
2025-09-03 11:03       ` Nautiyal, Ankit K
2025-09-03 12:24 ` Kahola, Mika
2025-09-03 13:38 ` ✗ Xe.CI.Full: failure for " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29e10fcd0e9bf9e995739cf53ae8f49544ebb06a@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=ankit.k.nautiyal@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox