Re: [PATCH v3] drm/i915/display: Check some INVALID_TRANSCODER cases

Jani Nikula <[email protected]>
Newsgroups org.freedesktop.lists.intel-gfx
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs Bertel Jungin Aukio 5, 02600 Espoo, Finland
Message-ID <[email protected]>
On Mon, 17 Aug 2026, Jonathan Cavitt <[email protected]> wrote:
> There are some cases in intel_ddi.c, such as in intel_ddi_is_audio_enabled
> and intel_ddi_compute_config_late, where we attempt to perform a BIT
> shift using a passed transcoder enum value.  This value may be -1,
> INVALID_TRANSCODER, which can result in undefined behavior if this
> occurs.
>
> In the former case, we can simply return false if this is the transcoder
> passed (as audio is not enabled on an invalid transcoder).
>
> In the latter case, the likely expected behavior is to set the
> crtc_state->sync_mode_slaves_mask to zero, so just do that directly and
> avoid a risky bit shift.
>
> The likelihood of either case occurring during normal execution is
> unknown and possibly very low.  Regardless, this covers a static analyis
> issue.
>
> v2: Rewrite the latter case to streamline it (Ville)
>
> v3: Target cpu_transcoder in intel_ddi_compute_config_late change (Jani)
>
> Signed-off-by: Jonathan Cavitt <[email protected]>
> Cc: Ville Syrjälä <[email protected]>
> Cc: Jani Nikula <[email protected]>
> ---
>  drivers/gpu/drm/i915/display/intel_ddi.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> index 9b3b526e5e55..2bfbb6297b5d 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> @@ -3893,7 +3893,8 @@ static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp,
>  static bool intel_ddi_is_audio_enabled(struct intel_display *display,
>  				       enum transcoder cpu_transcoder)
>  {
> -	if (cpu_transcoder == TRANSCODER_EDP)
> +	if (cpu_transcoder == TRANSCODER_EDP ||
> +	    cpu_transcoder == INVALID_TRANSCODER)
>  		return false;
>  
>  	if (!intel_display_power_is_enabled(display, POWER_DOMAIN_AUDIO_MMIO))
> @@ -4679,6 +4680,10 @@ static int intel_ddi_compute_config_late(struct intel_atomic_state *state,
>  
>  	if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) {
>  		crtc_state->master_transcoder = INVALID_TRANSCODER;
> +		if (crtc_state->cpu_transcoder == INVALID_TRANSCODER) {
> +			crtc_state->sync_mode_slaves_mask = 0;
> +			return 0;
> +		}
>  		crtc_state->sync_mode_slaves_mask = port_sync_transcoders &
>  			~REG_BIT(crtc_state->cpu_transcoder);

What I dislike about this is the crtc_state->cpu_transcoder being
INVALID_TRANSCODER now looks like a normal state of things, which it
isn't.

Adding checks for it reinforces the idea that you should check for it
everywhere. Which you shouldn't.

In the code path being checked, crtc_state->master_transcoder also ends
up being INVALID_TRANSCODER by coincidence, through a ffs(0) - 1
computation. We should never end up with INVALID_TRANSCODER as a result
of a computation like that. It should always be explicit
INVALID_TRANSCODER through other checks, i.e. port_sync_transcoders
being 0 in this case.


BR,
Jani.





>  	}

-- 
Jani Nikula, Intel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.