]> www.infradead.org Git - users/hch/configfs.git/commitdiff
drm/amd/display: Add NULL check for clk_mgr and clk_mgr->funcs in dcn401_init_hw
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Mon, 22 Jul 2024 11:28:32 +0000 (16:58 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 23 Jul 2024 21:42:29 +0000 (17:42 -0400)
This commit addresses a potential null pointer dereference issue in the
`dcn401_init_hw` function. The issue could occur when `dc->clk_mgr` or
`dc->clk_mgr->funcs` is null.

The fix adds a check to ensure `dc->clk_mgr` and `dc->clk_mgr->funcs` 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 <chiahsuan.chung@amd.com>
Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Cc: Roman Li <roman.li@amd.com>
Cc: Alex Hung <alex.hung@amd.com>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Hamza Mahfooz <hamza.mahfooz@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c

index 87c5ef579ecbbd9d74d9cc01f9e3cac927342836..0fa61059024558dd778b0157e19b91a9d204da9b 100644 (file)
@@ -222,7 +222,7 @@ void dcn401_init_hw(struct dc *dc)
        uint32_t backlight = MAX_BACKLIGHT_LEVEL;
        uint32_t user_level = MAX_BACKLIGHT_LEVEL;
 
-       if (dc->clk_mgr && dc->clk_mgr->funcs->init_clocks) {
+       if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->init_clocks) {
                dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
 
                // mark dcmode limits present if any clock has distinct AC and DC values from SMU
@@ -413,7 +413,7 @@ 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 && dc->clk_mgr->funcs->notify_wm_ranges)
                dc->clk_mgr->funcs->notify_wm_ranges(dc->clk_mgr);
 
        if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
@@ -435,7 +435,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);
                }
        }
 }