Skip to contentSkip to conversation

drm/amd/display: Fix missing NULL check in dcn21_set_backlight_level()

PATCH New Nikita Zhandarovich 1 participant 1 message Feb 8, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: Fix missing NULL check in dcn21_set_backlight_level()

On the off chance 'panel_cntl' ends up being not properly initialized, dcn21_set_backlight_level() may hit NULL pointer dereference while changing embedded panel backlight levels.

Prevent this issue by using some of the existing checks for the similar purpose. At the same time clean up redundant tests for NULL in 'abm'.

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 6f0ef80a00ad ("drm/amd/display: Fix ABM pipe/backlight issues when change backlight")
---
 drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c +8 -7
index 8e88dcaf88f5..2b1b580541a8 100644
@@ -247,7 +247,7 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx,
 	if (abm != NULL) {
 		uint32_t otg_inst = pipe_ctx->stream_res.tg->inst;
 
-		if (abm && panel_cntl) {
+		if (panel_cntl) {
 			if (abm->funcs && abm->funcs->set_pipe_ex) {
 				abm->funcs->set_pipe_ex(abm,
 						otg_inst,
@@ -261,15 +261,16 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx,
 							panel_cntl->inst,
 							panel_cntl->pwrseq_inst);
 			}
+
+			if (abm->funcs && abm->funcs->set_backlight_level_pwm)
+				abm->funcs->set_backlight_level_pwm(abm, backlight_pwm_u16_16,
+					frame_ramp, 0, panel_cntl->inst);
+			else
+				dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp,
+					panel_cntl->inst);
 		}
 	}
 
-	if (abm && abm->funcs && abm->funcs->set_backlight_level_pwm)
-		abm->funcs->set_backlight_level_pwm(abm, backlight_pwm_u16_16,
-			frame_ramp, 0, panel_cntl->inst);
-	else
-		dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp, panel_cntl->inst);
-
 	return true;
 }