]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Jul 2024 10:50:59 +0000 (12:50 +0200)
[ Upstream commit 8e65a1b7118acf6af96449e1e66b7adbc9396912 ]

[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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
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 3271c8c7905ddc4bf9a7e800b9fcef449e49dae6..4e036356b6a89aae66f610fbbd9ccc36bed465cb 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 e506e4f969ca9ffc90bdf8714c936a72aa9c2b17..dda1173be35ea2673bb2cdcd722aa9babe9b2f96 100644 (file)
@@ -1208,11 +1208,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 ecc477ef8e3b78e1705b8546ac17e1d8490982f7..b427a98066c1138fcd0be06d3258c39b0a0a4029 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 2fb1d00ff96549494124c03c3c6668c1ca948693..f38de5391176fbdc83eaf8f40cf5a37ccd85f9c0 100644 (file)
@@ -1311,6 +1311,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],
@@ -1767,6 +1769,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 c97391edb5ff7a43e437901004db526c31fdd54c..2791fc45bb8c78fe7d922e925118aef522c5489d 100644 (file)
@@ -1384,6 +1384,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],
@@ -1744,6 +1746,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 b9753d4606f89d53d709e4f2bbb9c3e0f4dc0928..efa5627b0c50abe1b81241970cbf4b3bfe228f4d 100644 (file)
@@ -1306,6 +1306,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 ce1754cc1f4631bcb800891ab7bd74ad52a36a69..1f5a91b764828d610d1bf595b6eea92521627837 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 296a0a8e71459f79f8478569287bd11dcae50cad..e83d340ed6260bc782b00eb71ef5787841d5c597 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 5d52853cac96abd82c795e8539ebba6d6d48555a..cf0cb5cf4b5b2c3e4666cbf3f29123c396944da8 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 909e14261f9b49aa5453fe0b9b5199d32ddc272a..116b59123199f9c48ffc428bbae1f67a9c522ad2 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