drm/amd/display: Add NULL pointer check for kzalloc
authorHersen Wu <hersenxs.wu@amd.com>
Mon, 22 Apr 2024 16:27:34 +0000 (12:27 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 26 Apr 2024 21:22:43 +0000 (17:22 -0400)
[Why & How]
Check return pointer of kzalloc before using it.

Reviewed-by: Alex Hung <alex.hung@amd.com>
Acked-by: Wayne Lin <wayne.lin@amd.com>
Signed-off-by: Hersen Wu <hersenxs.wu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c
drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c

index 4cb0db0ed92f748d640c1df444441953621656c3..8083a553c60e888e148439dc3305adc879a9d3ea 100644 (file)
@@ -560,11 +560,19 @@ void dcn3_clk_mgr_construct(
        dce_clock_read_ss_info(clk_mgr);
 
        clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
+       if (!clk_mgr->base.bw_params) {
+               BREAK_TO_DEBUGGER();
+               return;
+       }
 
        /* need physical address of table to give to PMFW */
        clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
                        DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
                        &clk_mgr->wm_range_table_addr);
+       if (!clk_mgr->wm_range_table) {
+               BREAK_TO_DEBUGGER();
+               return;
+       }
 }
 
 void dcn3_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)
index d7bbb0891398ef8b83e5bde24e115916447c348d..b9e1f3e0b31d7e4a03775c9ad829c1cd52fcab8c 100644 (file)
@@ -1199,11 +1199,19 @@ void dcn32_clk_mgr_construct(
        clk_mgr->smu_present = false;
 
        clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
+       if (!clk_mgr->base.bw_params) {
+               BREAK_TO_DEBUGGER();
+               return;
+       }
 
        /* need physical address of table to give to PMFW */
        clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
                        DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
                        &clk_mgr->wm_range_table_addr);
+       if (!clk_mgr->wm_range_table) {
+               BREAK_TO_DEBUGGER();
+               return;
+       }
 }
 
 void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)
index 237e00ea3e9403cfb42de2717868ecca40e6a1c9..f35cc307830beaf19430122c85d049bb040c6c86 100644 (file)
@@ -2050,6 +2050,9 @@ bool dcn30_validate_bandwidth(struct dc *dc,
 
        BW_VAL_TRACE_COUNT();
 
+       if (!pipes)
+               goto validate_fail;
+
        DC_FP_START();
        out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
        DC_FP_END();
index ecec3b69bb8800f86585040721bd4d2f913e1209..d4c3e2754f51671d6db1cd3e85517fef1d646b84 100644 (file)
@@ -1310,6 +1310,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
        hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
                                        &hpo_dp_link_enc_regs[inst],
@@ -1766,6 +1768,9 @@ bool dcn31_validate_bandwidth(struct dc *dc,
 
        BW_VAL_TRACE_COUNT();
 
+       if (!pipes)
+               goto validate_fail;
+
        DC_FP_START();
        out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
        DC_FP_END();
index 3bae606ed70075096e6cf1370e0c0c7215f5f5d7..ff50f43e4c000595f427d53a3f8d59f6f55483f6 100644 (file)
@@ -1367,6 +1367,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
        hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
                                        &hpo_dp_link_enc_regs[inst],
@@ -1727,6 +1729,9 @@ bool dcn314_validate_bandwidth(struct dc *dc,
 
        BW_VAL_TRACE_COUNT();
 
+       if (!pipes)
+               goto validate_fail;
+
        if (filter_modes_for_single_channel_workaround(dc, context))
                goto validate_fail;
 
index 515ba435f759c8dcb143ac3478b6914516b5f853..4ce0f4bf1d9bb1adaaf9555b7f3faac7e860283a 100644 (file)
@@ -1309,6 +1309,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
        hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
                                        &hpo_dp_link_enc_regs[inst],
index e808231e84788d4e823787f508b158c82919b625..5fd52c5fcee4585d95dd592ba922930f529c56a0 100644 (file)
@@ -1305,6 +1305,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
        hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
                                        &hpo_dp_link_enc_regs[inst],
index c16e915686fca573da7667060a68b03caf6857af..abd76345d1e430585d68fa0260fc8f676d34fcbe 100644 (file)
@@ -1304,6 +1304,8 @@ static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
 #undef REG_STRUCT
 #define REG_STRUCT hpo_dp_link_enc_regs
@@ -1751,6 +1753,9 @@ static bool dml1_validate(struct dc *dc, struct dc_state *context, bool fast_val
 
        BW_VAL_TRACE_COUNT();
 
+       if (!pipes)
+               goto validate_fail;
+
        DC_FP_START();
        out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
        DC_FP_END();
index 3816678b044f512b26880a5c30fef72b335f982c..e4b360d89b3be70a2d78a8d899fe7b329d50cef1 100644 (file)
@@ -1288,6 +1288,8 @@ static struct hpo_dp_link_encoder *dcn321_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
 #undef REG_STRUCT
 #define REG_STRUCT hpo_dp_link_enc_regs
index 25ac450944e74a67f3218bda474f41adfcba5626..2df8a742516c87d68e4e60bc8296fe29b55352c8 100644 (file)
@@ -1368,6 +1368,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
 #undef REG_STRUCT
 #define REG_STRUCT hpo_dp_link_enc_regs
index 3acfbbac8538f95f7b4d7bef5f9efe44e0d2c423..ddf9560ab7722c5edd748fd87d9cd436e5be5b0e 100644 (file)
@@ -1348,6 +1348,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
 
        /* allocate HPO link encoder */
        hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
+       if (!hpo_dp_enc31)
+               return NULL; /* out of memory */
 
 #undef REG_STRUCT
 #define REG_STRUCT hpo_dp_link_enc_regs