drm/amd/display: Fix divide-by-zero in calculate_mcache_setting on zero viewport
authorGeorge Zhang <george.zhang@amd.com>
Thu, 16 Jul 2026 21:00:01 +0000 (17:00 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 29 Jul 2026 00:00:20 +0000 (20:00 -0400)
commitf327e389c07cfc3a2f6ff54f6214e1a52d457edc
tree8d05cb70a165f91be4f3ab4ce731cb6cad2d4d07
parent443290d70b01e9c35830c300e3247c06581b594c
drm/amd/display: Fix divide-by-zero in calculate_mcache_setting on zero viewport

If a plane reaches calculate_mcache_setting with a zero-area viewport,
calculate_mcache_setting exits early with num_mcaches == 0 and
mvmpg_width/height == 0. This will cause a divide-by-zero panic and can
also cause an underflow on num_mcaches.

Fix this by changing calculate_mcache_setting to bool and adding guards
after each calculate_mcache_row_bytes call. If num_mcaches or
mvmpg_width/height is zero, return a false. Callers will propagate the
failure as a rejected mode, which prevents the panic.

Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/5302
Reviewed-by: Sun peng (Leo) Li <sunpeng.li@amd.com>
Reviewed-by: Dillon Varone <dillon.varone@amd.com>
Signed-off-by: George Zhang <george.zhang@amd.com>
Signed-off-by: Fangzhi Zuo <jerry.zuo@amd.com>
Tested-by: Dan Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 29c0f7c655f47bcbd575ff75e58480df6ec3c9da)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c