From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com>,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/hdmi: Fix potential overflow while using intel_encoder_to_tc
Date: Wed, 03 Sep 2025 13:16:27 +0300 [thread overview]
Message-ID: <f39482b5b85dfe3e89328ce32ada5f931ed34519@intel.com> (raw)
In-Reply-To: <bdeae305-c155-4a6e-9d6f-32f44d425ebf@intel.com>
On Wed, 03 Sep 2025, "Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com> wrote:
> On 9/3/2025 1:07 PM, Jani Nikula wrote:
>> 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.
>
> Agreed, in this case tc_port is valid, I can see that now.
>
>
>>
>> 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.
>
> Hmm.. I can try this out. Can change intel_port_to_tc() as suggested and
> ensure the callers call intel_phy_is_tc(),
>
> before calling intel_port_to_tc()/intel_encoder_to_tc().
>
> There are few places where the callers of intel_port_to_tc() and
> intel_encoder_to_tc() specifically check for TC_PORT_NONE,
>
> so those places need to be changed as well.
>
>
> Thanks for the suggestions and comments. I will drop this patch, and
> will prepare for the suggested changes.
I think with those changes you can eradicate TC_PORT_NONE altogether,
and get rid of a whole class of static analyzer warnings. And the code
becomes cleaner all around.
I've had this patch [1] for more than a year, maybe finally time to
merge it as prep work. You'll need to add tc checks in there, so it's
cleaner to lift it from intel_ddi_init(). And you can have separate code
paths for tc and non-tc, making the whole thing much cleaner I think.
BR,
Jani.
[1] https://lore.kernel.org/r/20250903101050.3671305-1-jani.nikula@intel.com
>
> Regards,
>
> Ankit
>
>>
>> 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
next prev parent reply other threads:[~2025-09-03 10:16 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 ` [PATCH] " Jani Nikula
2025-09-03 9:57 ` Nautiyal, Ankit K
2025-09-03 10:16 ` Jani Nikula [this message]
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=f39482b5b85dfe3e89328ce32ada5f931ed34519@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