From: Hersen Wu hersenxs.wu@amd.com
[ 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 [ Resolve minor conflicts ] Signed-off-by: Bin Lan bin.lan.cn@windriver.com --- .../gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c | 8 ++++++++ .../gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c | 8 ++++++++ drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c | 3 +++ drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c | 5 +++++ drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c | 5 +++++ drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c | 2 ++ drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c | 2 ++ drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c | 5 +++++ drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c | 2 ++ 9 files changed, 40 insertions(+)
diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c index 3271c8c7905d..4e036356b6a8 100644 --- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c +++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c @@ -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) diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c index 2428a4763b85..1c5ae4d62e37 100644 --- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c +++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c @@ -1022,11 +1022,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) diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c index 88c0b24a3249..de83acd12250 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c @@ -2045,6 +2045,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(); diff --git a/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c b/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c index 82de4fe2637f..84e3df49be2f 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c @@ -1308,6 +1308,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], @@ -1764,6 +1766,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(); diff --git a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c index 3e65e683db0a..6e52851bc031 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c @@ -1381,6 +1381,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], @@ -1741,6 +1743,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;
diff --git a/drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c b/drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c index 127487ea3d7d..3f3b555b4523 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c @@ -1308,6 +1308,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], diff --git a/drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c b/drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c index 5fe2c61527df..37b7973fc949 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c @@ -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], diff --git a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c index f9d601c8c721..4d4ff13a2af8 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c @@ -1299,6 +1299,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 @@ -1842,6 +1844,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(); diff --git a/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c b/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c index aa4c64eec7b3..4289cd1643ec 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c +++ b/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c @@ -1285,6 +1285,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
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: 8e65a1b7118acf6af96449e1e66b7adbc9396912
WARNING: Author mismatch between patch and upstream commit: Backport author: bin.lan.cn@eng.windriver.com Commit author: Hersen Wu hersenxs.wu@amd.com
Status in newer kernel trees: 6.12.y | Present (exact SHA1) 6.11.y | Present (exact SHA1) 6.6.y | Not found
Note: The patch differs from the upstream commit: --- 1: 8e65a1b7118ac ! 1: a22a302a24281 drm/amd/display: Add NULL pointer check for kzalloc @@ Metadata ## Commit message ## drm/amd/display: Add NULL pointer check for kzalloc
+ [ Upstream commit 8e65a1b7118acf6af96449e1e66b7adbc9396912 ] + [Why & How] Check return pointer of kzalloc before using it.
@@ Commit message 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 + [ Resolve minor conflicts ] + Signed-off-by: Bin Lan bin.lan.cn@windriver.com
## drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c ## @@ drivers/gpu/drm/amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c: void dcn3_clk_mgr_construct( @@ drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c: void dcn32_clk_mgr
void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr)
- ## drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c: bool dcn30_validate_bandwidth(struct dc *dc, + ## drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c: bool dcn30_validate_bandwidth(struct dc *dc,
BW_VAL_TRACE_COUNT();
@@ drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c: bool dcn30_valid out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true); DC_FP_END();
- ## drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c: static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c: 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); @@ drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c: static struct hp
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst, &hpo_dp_link_enc_regs[inst], -@@ drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c: bool dcn31_validate_bandwidth(struct dc *dc, +@@ drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c: bool dcn31_validate_bandwidth(struct dc *dc,
BW_VAL_TRACE_COUNT();
@@ drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c: bool dcn31_valid out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true); DC_FP_END();
- ## drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c: static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c: 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); @@ drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c: static struct
hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst, &hpo_dp_link_enc_regs[inst], -@@ drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c: bool dcn314_validate_bandwidth(struct dc *dc, +@@ drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c: bool dcn314_validate_bandwidth(struct dc *dc,
BW_VAL_TRACE_COUNT();
@@ drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c: bool dcn314_va goto validate_fail;
- ## drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c: static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn315/dcn315_resource.c: 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); @@ drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c: static struct hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst, &hpo_dp_link_enc_regs[inst],
- ## drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c: static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn316/dcn316_resource.c: 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); @@ drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c: static struct hpo_dp_link_encoder31_construct(hpo_dp_enc31, ctx, inst, &hpo_dp_link_enc_regs[inst],
- ## drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c: static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c: 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); @@ drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c: static struct hp
#undef REG_STRUCT #define REG_STRUCT hpo_dp_link_enc_regs -@@ drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c: static bool dml1_validate(struct dc *dc, struct dc_state *context, bool fast_val +@@ drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c: bool dcn32_validate_bandwidth(struct dc *dc,
BW_VAL_TRACE_COUNT();
@@ drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c: static bool dml1 out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate); DC_FP_END();
- ## drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c: 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 - - ## drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c: 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 - - ## drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c ## -@@ drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c: static struct hpo_dp_link_encoder *dcn31_hpo_dp_link_encoder_create( + ## drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c ## +@@ drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c: 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); ---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.6.y | Success | Success |
linux-stable-mirror@lists.linaro.org