This commit addresses a potential null pointer dereference issue in the
`dcn401_init_hw` function. The issue could occur when `dc->clk_mgr` is
null.

The fix adds a check to ensure `dc->clk_mgr` is not null before
accessing its functions. This prevents a potential null pointer
dereference.

Reported by smatch:
drivers/gpu/drm/amd/amdgpu/../display/dc/hwss/dcn401/dcn401_hwseq.c:416 
dcn401_init_hw() error: we previously assumed 'dc->clk_mgr' could be null (see 
line 225)

Cc: Tom Chung <[email protected]>
Cc: Rodrigo Siqueira <[email protected]>
Cc: Roman Li <[email protected]>
Cc: Alex Hung <[email protected]>
Cc: Aurabindo Pillai <[email protected]>
Cc: Harry Wentland <[email protected]>
Cc: Hamza Mahfooz <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
---
 .../gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c    | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c 
b/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
index f4c1547a368f..16ffb41abc6d 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
@@ -413,10 +413,11 @@ void dcn401_init_hw(struct dc *dc)
        if (!dcb->funcs->is_accelerated_mode(dcb) && 
dc->res_pool->hubbub->funcs->init_watermarks)
                
dc->res_pool->hubbub->funcs->init_watermarks(dc->res_pool->hubbub);
 
-       if (dc->clk_mgr->funcs->notify_wm_ranges)
+       if (dc->clk_mgr && dc->clk_mgr->funcs->notify_wm_ranges)
                dc->clk_mgr->funcs->notify_wm_ranges(dc->clk_mgr);
 
-       if (dc->clk_mgr->funcs->set_hard_max_memclk && 
!dc->clk_mgr->dc_mode_softmax_enabled)
+       if (dc->clk_mgr && dc->clk_mgr->funcs->set_hard_max_memclk &&
+           !dc->clk_mgr->dc_mode_softmax_enabled)
                dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
 
        if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
@@ -438,7 +439,9 @@ void dcn401_init_hw(struct dc *dc)
                dc->debug.fams2_config.bits.enable &= 
dc->ctx->dmub_srv->dmub->feature_caps.fw_assisted_mclk_switch_ver == 2;
                if (!dc->debug.fams2_config.bits.enable && 
dc->res_pool->funcs->update_bw_bounding_box) {
                        /* update bounding box if FAMS2 disabled */
-                       dc->res_pool->funcs->update_bw_bounding_box(dc, 
dc->clk_mgr->bw_params);
+                       if (dc->clk_mgr)
+                               dc->res_pool->funcs->update_bw_bounding_box(dc,
+                                                                           
dc->clk_mgr->bw_params);
                }
        }
 }
-- 
2.34.1

Reply via email to