[PATCH v4] drm/i915/display: Check some INVALID_TRANSCODER cases
Jonathan Cavitt <[email protected]>
| Newsgroups | org.freedesktop.lists.intel-gfx |
|---|---|
| Message-ID | <[email protected]> |
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) v4: - Directly set master_transcoder = INVALID_TRANSCODER in the port_sync_transcoders == 0 case (Jani) - Reorganize cpu_transcoder == master_transcoder segment, as master_transcoder no longer needs to be reassigned in the INVALID_TRANSCODER case (jcavitt) - Add a comment explaining the change (jcavitt) 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 | 19 ++++++++++++++++++- 1 file changed, 18 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..d3131dcf6356 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)) @@ -4674,10 +4675,26 @@ static int intel_ddi_compute_config_late(struct intel_atomic_state *state, */ if (port_sync_transcoders & BIT(TRANSCODER_EDP)) crtc_state->master_transcoder = TRANSCODER_EDP; + else if (!port_sync_transcoders) + crtc_state->master_transcoder = INVALID_TRANSCODER; else crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1; if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) { + if (crtc_state->cpu_transcoder == INVALID_TRANSCODER) { + /* + * Since master_transcoder == cpu_transcoder, + * master_transcoder == INVALID_TRANSCODER, so we don't need to do + * the later assignment. Also, the intended behavior in this case + * is to just set the sync_mode_slaves_mask to zero, as + * port_sync_transcoders must be zero here. But performing a bit + * shift (via REG_BIT) by a negative value results in undefined + * behavior which should always be avoided, so just do the + * assignment to zero directly and return. + */ + crtc_state->sync_mode_slaves_mask = 0; + return 0; + } crtc_state->master_transcoder = INVALID_TRANSCODER; crtc_state->sync_mode_slaves_mask = port_sync_transcoders & ~REG_BIT(crtc_state->cpu_transcoder); -- 2.53.0