Skip to contentSkip to conversation

drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...)

PATCH In review Ethan Carter Edwards 3 participants 7 messages Feb 27, 2025 – Mar 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...)

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplications are probably safe, but using kcalloc() is more appropriate and improves readability. It is also safer. This series contains a few patches with these fixes.

Part of the Kernel Self Protection Project efforts. Links below have more details.

---
Ethan Carter Edwards (4):
drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dml1_validate()

 drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c   | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c   | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

---
base-commit: be5c7bbb3a64baf884481a1ba0c2f8fb2f93f7c3
change-id: 20250227-amd-display-a8342c55a9a0

Best regards,

Signature · 1 line
Ethan Carter Edwards <[email protected]>
#1 lore raw

PATCH 1/4 drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth()

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is probably safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c +2 -1
index 13202ce30d668e0c9e66632a9016a1597e2705b2..f01ced0150726b2efbd123de0084101cfc763ff5 100644
@@ -2047,7 +2047,8 @@ bool dcn30_validate_bandwidth(struct dc *dc,
 
 	int vlevel = 0;
 	int pipe_cnt = 0;
-	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
+	display_e2e_pipe_params_st *pipes = kcalloc(dc->res_pool->pipe_count,
+			sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
 	DC_LOGGER_INIT(dc->ctx->logger);
 
 	BW_VAL_TRACE_COUNT();
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/4 drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth()

In reply to Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is probably safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c +2 -1
index 3c42ba8566cf8b79106de25c9e0aad4a70898ea6..dddddbfef85f8f65a6f76c86cbb6db59d608a74b 100644
@@ -1768,7 +1768,8 @@ bool dcn31_validate_bandwidth(struct dc *dc,
 
 	int vlevel = 0;
 	int pipe_cnt = 0;
-	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
+	display_e2e_pipe_params_st *pipes = kcalloc(dc->res_pool->pipe_count,
+			sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
 	DC_LOGGER_INIT(dc->ctx->logger);
 
 	BW_VAL_TRACE_COUNT();
Signature · 1 line
2.48.1
#3 lore raw

PATCH 3/4 drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth()

In reply to Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is probably safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c +2 -1
index e3ba105034f83434c3e77d343ee267069d34d926..26becc4cb80408cb2778f6af62c7a1c497f06505 100644
@@ -1704,7 +1704,8 @@ bool dcn314_validate_bandwidth(struct dc *dc,
 
 	int vlevel = 0;
 	int pipe_cnt = 0;
-	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
+	display_e2e_pipe_params_st *pipes = kcalloc(dc->res_pool->pipe_count,
+			sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
 	DC_LOGGER_INIT(dc->ctx->logger);
 
 	BW_VAL_TRACE_COUNT();
Signature · 1 line
2.48.1
#4 lore raw

PATCH 4/4 drm/amd/display: change kzalloc to kcalloc in dml1_validate()

In reply to Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is probably safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +2 -1
index 664302876019072a77b9330229f7fe8545787396..2a59cc61ed8c918a4b5beb1d90bf3a8f77fcdeb9 100644
@@ -1749,7 +1749,8 @@ static bool dml1_validate(struct dc *dc, struct dc_state *context, bool fast_val
 
 	int vlevel = 0;
 	int pipe_cnt = 0;
-	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
+	display_e2e_pipe_params_st *pipes = kcalloc(dc->res_pool->pipe_count,
+			sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
 
 	/* To handle Freesync properly, setting FreeSync DML parameters
 	 * to its default state for the first stage of validation
Signature · 1 line
2.48.1
reviewer Reviewed-by on the v1 series
#5 lore raw
In reply to Ethan Carter Edwards
Quoted 25 lines · Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplications are probably safe, but using kcalloc() is more appropriate and improves readability. It is also safer. This series contains a few patches with these fixes.

Part of the Kernel Self Protection Project efforts. Links below have more details.

---
Ethan Carter Edwards (4):
drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dml1_validate()

 drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c   | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c   | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c | 3 ++-
 drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)
Quoted 8 lines

---
base-commit: be5c7bbb3a64baf884481a1ba0c2f8fb2f93f7c3
change-id: 20250227-amd-display-a8342c55a9a0

Best regards,

Signature · 1 line
Ethan Carter Edwards <[email protected]>

Hi,

This series LGTM,

To Display folks,
(Cc some other devs)

If possible, try to include this series in this week's promotion tests, or check the IGT test in the CI just to be safe.

Thanks

Signature · 1 line
Rodrigo Siqueira
Reviewed-by on the v1 series
#6 lore raw
In reply to Ethan Carter Edwards

This series LGTM too.

Quoted 30 lines · Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplications are probably safe, but using kcalloc() is more appropriate and improves readability. It is also safer. This series contains a few patches with these fixes.

Part of the Kernel Self Protection Project efforts. Links below have more details.

---
Ethan Carter Edwards (4):
drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() drm/amd/display: change kzalloc to kcalloc in dml1_validate()

  drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c   | 3 ++-
  drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c   | 3 ++-
  drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c | 3 ++-
  drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c   | 3 ++-
  4 files changed, 8 insertions(+), 4 deletions(-)

---
base-commit: be5c7bbb3a64baf884481a1ba0c2f8fb2f93f7c3
change-id: 20250227-amd-display-a8342c55a9a0

Best regards,