[why] Prevent index-out-of-bounds due to requiring cursor overlay when plane_count is MAX_SURFACES. [how] Bounds check on plane_count when requiring overlay cursor. Co-developed-by: Melissa Wen <mwen@xxxxxxxxxx> Signed-off-by: Zaeem Mohamed <zaeem.mohamed@xxxxxxx> --- amdgpu_dm/amdgpu_dm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/amdgpu_dm/amdgpu_dm.c b/amdgpu_dm/amdgpu_dm.c index df83e7b42b..c2595efb74 100644 --- a/amdgpu_dm/amdgpu_dm.c +++ b/amdgpu_dm/amdgpu_dm.c @@ -11676,6 +11676,12 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, * need to be added for DC to not disable a plane by mistake */ if (dm_new_crtc_state->cursor_mode == DM_CURSOR_OVERLAY_MODE) { + if(dc->current_state->stream_status->plane_count >= MAX_SURFACES){ + drm_dbg_driver(crtc->dev, + "Can't enable cursor plane with %d planes\n", MAX_SURFACES); + ret = -EINVAL; + goto fail; + } ret = drm_atomic_add_affected_planes(state, crtc); if (ret) goto fail; @@ -11769,8 +11775,16 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, /* Overlay cusor not subject to native cursor restrictions */ dm_new_crtc_state = to_dm_crtc_state(new_crtc_state); - if (dm_new_crtc_state->cursor_mode == DM_CURSOR_OVERLAY_MODE) + if (dm_new_crtc_state->cursor_mode == DM_CURSOR_OVERLAY_MODE){ + if(dc->current_state->stream_status->plane_count > MAX_SURFACES){ + drm_dbg_driver(crtc->dev, + "Can't enable cursor plane with %d planes\n", MAX_SURFACES); + ret = -EINVAL; + goto fail; + } + continue; + } /* Check if rotation or scaling is enabled on DCN401 */ if ((drm_plane_mask(crtc->cursor) & new_crtc_state->plane_mask) && -- 2.34.1