Add a drm_WARN_ON() in intel_crtc_init() to catch cases where
crtc->num_scalers exceeds the expected SKL_NUM_SCALERS limit.

This condition should not occur, as the number of scalers per pipe does not
exceed two for current platforms, making SKL_NUM_SCALERS (2) a safer upper
limit. However, if a platform ever gains more scalers per pipe than
SKL_NUM_SCALERS, it could lead to issues when crtc->num_scalers is used to
iterate over scaler_state->scalers.

To prevent this, warn and clamp the value to SKL_NUM_SCALERS.

Suggested-by: Jani Nikula <jani.nik...@intel.com>
Signed-off-by: Ankit Nautiyal <ankit.k.nauti...@intel.com>
---
 drivers/gpu/drm/i915/display/intel_crtc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_crtc.c 
b/drivers/gpu/drm/i915/display/intel_crtc.c
index a187db6df2d3..e262e686dc2b 100644
--- a/drivers/gpu/drm/i915/display/intel_crtc.c
+++ b/drivers/gpu/drm/i915/display/intel_crtc.c
@@ -317,6 +317,9 @@ int intel_crtc_init(struct intel_display *display, enum 
pipe pipe)
        crtc->pipe = pipe;
        crtc->num_scalers = DISPLAY_RUNTIME_INFO(display)->num_scalers[pipe];
 
+       if (drm_WARN_ON(display->drm, crtc->num_scalers > SKL_NUM_SCALERS))
+               crtc->num_scalers = SKL_NUM_SCALERS;
+
        if (DISPLAY_VER(display) >= 9)
                primary = skl_universal_plane_create(display, pipe, PLANE_1);
        else
-- 
2.45.2

Reply via email to