Skip to content

Commit 552e793

Browse files
Hersen Wugregkh
authored andcommitted
drm/amd/display: Add NULL pointer check for kzalloc
commit 8e65a1b7118acf6af96449e1e66b7adbc9396912 upstream. [Why & How] Check return pointer of kzalloc before using it. Reviewed-by: Alex Hung <[email protected]> Acked-by: Wayne Lin <[email protected]> Signed-off-by: Hersen Wu <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Signed-off-by: Wenshan Lan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f81302d commit 552e793

File tree

9 files changed

+40
-0
lines changed

9 files changed

+40
-0
lines changed

drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,19 @@ void dcn3_clk_mgr_construct(
568568
dce_clock_read_ss_info(clk_mgr);
569569

570570
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
571+
if (!clk_mgr->base.bw_params) {
572+
BREAK_TO_DEBUGGER();
573+
return;
574+
}
571575

572576
/* need physical address of table to give to PMFW */
573577
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
574578
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
575579
&clk_mgr->wm_range_table_addr);
580+
if (!clk_mgr->wm_range_table) {
581+
BREAK_TO_DEBUGGER();
582+
return;
583+
}
576584
}
577585

578586
void dcn3_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)

drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,19 @@ void dcn32_clk_mgr_construct(
816816
clk_mgr->smu_present = false;
817817

818818
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
819+
if (!clk_mgr->base.bw_params) {
820+
BREAK_TO_DEBUGGER();
821+
return;
822+
}
819823

820824
/* need physical address of table to give to PMFW */
821825
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
822826
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
823827
&clk_mgr->wm_range_table_addr);
828+
if (!clk_mgr->wm_range_table) {
829+
BREAK_TO_DEBUGGER();
830+
return;
831+
}
824832
}
825833

826834
void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)

drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,9 @@ bool dcn30_validate_bandwidth(struct dc *dc,
20622062

20632063
BW_VAL_TRACE_COUNT();
20642064

2065+
if (!pipes)
2066+
goto validate_fail;
2067+
20652068
DC_FP_START();
20662069
out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
20672070
DC_FP_END();

drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
13241324

13251325
/* allocate HPO link encoder */
13261326
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1327+
if (!hpo_dp_enc31)
1328+
return NULL; /* out of memory */
13271329

13281330
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13291331
&hpo_dp_link_enc_regs[inst],
@@ -1773,6 +1775,9 @@ bool dcn31_validate_bandwidth(struct dc *dc,
17731775

17741776
BW_VAL_TRACE_COUNT();
17751777

1778+
if (!pipes)
1779+
goto validate_fail;
1780+
17761781
DC_FP_START();
17771782
out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
17781783
DC_FP_END();

drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
13721372

13731373
/* allocate HPO link encoder */
13741374
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1375+
if (!hpo_dp_enc31)
1376+
return NULL; /* out of memory */
13751377

13761378
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13771379
&hpo_dp_link_enc_regs[inst],
@@ -1743,6 +1745,9 @@ bool dcn314_validate_bandwidth(struct dc *dc,
17431745

17441746
BW_VAL_TRACE_COUNT();
17451747

1748+
if (!pipes)
1749+
goto validate_fail;
1750+
17461751
if (filter_modes_for_single_channel_workaround(dc, context))
17471752
goto validate_fail;
17481753

drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
13251325

13261326
/* allocate HPO link encoder */
13271327
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1328+
if (!hpo_dp_enc31)
1329+
return NULL; /* out of memory */
13281330

13291331
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13301332
&hpo_dp_link_enc_regs[inst],

drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,8 @@ static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create(
13221322

13231323
/* allocate HPO link encoder */
13241324
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1325+
if (!hpo_dp_enc31)
1326+
return NULL; /* out of memory */
13251327

13261328
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13271329
&hpo_dp_link_enc_regs[inst],

drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create(
13101310

13111311
/* allocate HPO link encoder */
13121312
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1313+
if (!hpo_dp_enc31)
1314+
return NULL; /* out of memory */
13131315

13141316
#undef REG_STRUCT
13151317
#define REG_STRUCT hpo_dp_link_enc_regs
@@ -1855,6 +1857,9 @@ bool dcn32_validate_bandwidth(struct dc *dc,
18551857

18561858
BW_VAL_TRACE_COUNT();
18571859

1860+
if (!pipes)
1861+
goto validate_fail;
1862+
18581863
DC_FP_START();
18591864
out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
18601865
DC_FP_END();

drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,8 @@ static struct hpo_dp_link_encoder *dcn321_hpo_dp_link_encoder_create(
12961296

12971297
/* allocate HPO link encoder */
12981298
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1299+
if (!hpo_dp_enc31)
1300+
return NULL; /* out of memory */
12991301

13001302
#undef REG_STRUCT
13011303
#define REG_STRUCT hpo_dp_link_enc_regs

0 commit comments

Comments
 (0)