[PATCH] drm/amd/display: use READ_ONCE() in psr_su_set_dsc_slice_height()
From: Dan Carpenter
Date: Mon May 25 2026 - 04:06:59 EST
This code has two checks for if "stream->timing.dsc_cfg.num_slices_v" is
zero so static checkers complain. The second check was added based on
real life crashes so it suggests there is a race condition. Use
READ_ONCE() to fix this more reliably.
In the original code we returns true for the first zero check and false
for the second check. The caller doesn't care about returns so it
doesn't matter whether we return true or false.
Fixes: 21fc0ff38f57 ("drm/amd/display: fix a divided-by-zero error")
Signed-off-by: Dan Carpenter <error27@xxxxxxxxx>
---
Untested. Just reviewing static checker warnings. I wanted a chance
to use READ_ONCE().
.../gpu/drm/amd/display/modules/power/power_psr.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/modules/power/power_psr.c b/drivers/gpu/drm/amd/display/modules/power/power_psr.c
index 5ecb570c204e..92c0aed08170 100644
--- a/drivers/gpu/drm/amd/display/modules/power/power_psr.c
+++ b/drivers/gpu/drm/amd/display/modules/power/power_psr.c
@@ -635,22 +635,23 @@ bool psr_su_set_dsc_slice_height(struct dc *dc, struct dc_link *link,
{
uint32_t pic_height;
uint32_t slice_height;
+ uint32_t num_slices_v;
config->dsc_slice_height = 0;
if (!(link->connector_signal & SIGNAL_TYPE_EDP) ||
!dc->caps.edp_dsc_support ||
link->panel_config.dsc.disable_dsc_edp ||
- !link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT ||
- !stream->timing.dsc_cfg.num_slices_v)
+ !link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT)
return true;
+ num_slices_v = READ_ONCE(stream->timing.dsc_cfg.num_slices_v);
+ if (!num_slices_v)
+ return false;
+
pic_height = stream->timing.v_addressable +
stream->timing.v_border_top + stream->timing.v_border_bottom;
- if (stream->timing.dsc_cfg.num_slices_v == 0)
- return false;
-
- slice_height = pic_height / stream->timing.dsc_cfg.num_slices_v;
+ slice_height = pic_height / num_slices_v;
config->dsc_slice_height = (uint16_t)slice_height;
if (slice_height) {
--
2.53.0