]> 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>
Fri, 21 Feb 2025 12:50:12 +0000 (13:50 +0100)
commit 8e65a1b7118acf6af96449e1e66b7adbc9396912 upstream.

[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: Wenshan Lan <jetlan9@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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/dcn30/dcn30_resource.c
drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c
drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c
drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c
drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c
drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c

index 3ce0ee0d012f341636766a46d84e536a34cb6224..367b163537c4b4624245f5aa2305dcbf6bac6098 100644 (file)
@@ -568,11 +568,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 1d84a04acb3f09df6a67422702ba655707218de5..3ade764d33230d7abe4ddcfc2bd395a3a0c910f9 100644 (file)
@@ -816,11 +816,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 5a8d1a05131493f23d6d97c86ac840510162ab38..6c58618f1b9ca046fefd609b7cd20bbf9f6f58bf 100644 (file)
@@ -2062,6 +2062,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 d3f76512841b4fe2be3d8c8b910ad39742fdb0b5..73a7b1ec353e06cca1e5350a05a40e8ffe10e889 100644 (file)
@@ -1324,6 +1324,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],
@@ -1773,6 +1775,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 6b8abdb5c7f8907d0303d9ee76a90f454287ecfd..1a4280b89a1f3669e1e57c08f0a4912f9856bbfd 100644 (file)
@@ -1372,6 +1372,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],
@@ -1743,6 +1745,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 b9b1e5ac4f538b51a8eec4238dbca106e4b1e418..e78954514e3e24ddff9bb43d6c76eb3111f2b60e 100644 (file)
@@ -1325,6 +1325,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 af3eddc0cf32ebdb4838198588cca17332ab942f..932fe9b5c08ce563878d5de5589ec2ec4c7d2062 100644 (file)
@@ -1322,6 +1322,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 ef47fb2f6905737c178d842f119423268efdb6d2..1b1534ffee9f128b952f751b5b376e2a3ce49d02 100644 (file)
@@ -1310,6 +1310,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
@@ -1855,6 +1857,9 @@ bool dcn32_validate_bandwidth(struct dc *dc,
 
        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 aed92ced7b762393178d553793c0e88d3589781a..85430e5baa455ae33a16bb62b745b2281e0a479b 100644 (file)
@@ -1296,6 +1296,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