Skip to content

Commit 8e65a1b

Browse files
Hersen Wualexdeucher
authored andcommitted
drm/amd/display: Add NULL pointer check for kzalloc
[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]>
1 parent b528cac commit 8e65a1b

File tree

11 files changed

+44
-0
lines changed

11 files changed

+44
-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
@@ -560,11 +560,19 @@ void dcn3_clk_mgr_construct(
560560
dce_clock_read_ss_info(clk_mgr);
561561

562562
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
563+
if (!clk_mgr->base.bw_params) {
564+
BREAK_TO_DEBUGGER();
565+
return;
566+
}
563567

564568
/* need physical address of table to give to PMFW */
565569
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
566570
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
567571
&clk_mgr->wm_range_table_addr);
572+
if (!clk_mgr->wm_range_table) {
573+
BREAK_TO_DEBUGGER();
574+
return;
575+
}
568576
}
569577

570578
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
@@ -1199,11 +1199,19 @@ void dcn32_clk_mgr_construct(
11991199
clk_mgr->smu_present = false;
12001200

12011201
clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
1202+
if (!clk_mgr->base.bw_params) {
1203+
BREAK_TO_DEBUGGER();
1204+
return;
1205+
}
12021206

12031207
/* need physical address of table to give to PMFW */
12041208
clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx,
12051209
DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t),
12061210
&clk_mgr->wm_range_table_addr);
1211+
if (!clk_mgr->wm_range_table) {
1212+
BREAK_TO_DEBUGGER();
1213+
return;
1214+
}
12071215
}
12081216

12091217
void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)

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

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

20512051
BW_VAL_TRACE_COUNT();
20522052

2053+
if (!pipes)
2054+
goto validate_fail;
2055+
20532056
DC_FP_START();
20542057
out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
20552058
DC_FP_END();

drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_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 *dcn31_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
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13151317
&hpo_dp_link_enc_regs[inst],
@@ -1766,6 +1768,9 @@ bool dcn31_validate_bandwidth(struct dc *dc,
17661768

17671769
BW_VAL_TRACE_COUNT();
17681770

1771+
if (!pipes)
1772+
goto validate_fail;
1773+
17691774
DC_FP_START();
17701775
out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
17711776
DC_FP_END();

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

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

13681368
/* allocate HPO link encoder */
13691369
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1370+
if (!hpo_dp_enc31)
1371+
return NULL; /* out of memory */
13701372

13711373
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13721374
&hpo_dp_link_enc_regs[inst],
@@ -1727,6 +1729,9 @@ bool dcn314_validate_bandwidth(struct dc *dc,
17271729

17281730
BW_VAL_TRACE_COUNT();
17291731

1732+
if (!pipes)
1733+
goto validate_fail;
1734+
17301735
if (filter_modes_for_single_channel_workaround(dc, context))
17311736
goto validate_fail;
17321737

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

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

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

13131315
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13141316
&hpo_dp_link_enc_regs[inst],

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

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

13061306
/* allocate HPO link encoder */
13071307
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1308+
if (!hpo_dp_enc31)
1309+
return NULL; /* out of memory */
13081310

13091311
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst,
13101312
&hpo_dp_link_enc_regs[inst],

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

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

13051305
/* allocate HPO link encoder */
13061306
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1307+
if (!hpo_dp_enc31)
1308+
return NULL; /* out of memory */
13071309

13081310
#undef REG_STRUCT
13091311
#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
17511753

17521754
BW_VAL_TRACE_COUNT();
17531755

1756+
if (!pipes)
1757+
goto validate_fail;
1758+
17541759
DC_FP_START();
17551760
out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
17561761
DC_FP_END();

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

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

12891289
/* allocate HPO link encoder */
12901290
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1291+
if (!hpo_dp_enc31)
1292+
return NULL; /* out of memory */
12911293

12921294
#undef REG_STRUCT
12931295
#define REG_STRUCT hpo_dp_link_enc_regs

drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c

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

13691369
/* allocate HPO link encoder */
13701370
hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1371+
if (!hpo_dp_enc31)
1372+
return NULL; /* out of memory */
13711373

13721374
#undef REG_STRUCT
13731375
#define REG_STRUCT hpo_dp_link_enc_regs

0 commit comments

Comments
 (0)