diff mbox series

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

Message ID 20240208123711.52333-1-n.zhandarovich@fintech.ru (mailing list archive)
State New, archived
Headers show
Series drm/amd/display: Fix missing NULL check in dcn21_set_backlight_level() | expand

Commit Message

Nikita Zhandarovich Feb. 8, 2024, 12:37 p.m. UTC
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")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
 drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
index 8e88dcaf88f5..2b1b580541a8 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
@@ -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;
 }