Linux Hardening
 help / color / mirror / Atom feed
* [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...)
@ 2025-02-27 23:16 Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 1/4] drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() Ethan Carter Edwards
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-02-27 23:16 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening,
	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.

Link: https://github.com/KSPP/linux/issues/162
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
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,
-- 
Ethan Carter Edwards <ethan@ethancedwards.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth()
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
@ 2025-02-27 23:16 ` Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 2/4] drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() Ethan Carter Edwards
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-02-27 23:16 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening,
	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.

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c
index 13202ce30d668e0c9e66632a9016a1597e2705b2..f01ced0150726b2efbd123de0084101cfc763ff5 100644
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c
@@ -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();

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth()
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 1/4] drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() Ethan Carter Edwards
@ 2025-02-27 23:16 ` Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 3/4] drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() Ethan Carter Edwards
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-02-27 23:16 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening,
	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.

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c
index 3c42ba8566cf8b79106de25c9e0aad4a70898ea6..dddddbfef85f8f65a6f76c86cbb6db59d608a74b 100644
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c
@@ -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();

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth()
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 1/4] drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 2/4] drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() Ethan Carter Edwards
@ 2025-02-27 23:16 ` Ethan Carter Edwards
  2025-02-27 23:16 ` [PATCH 4/4] drm/amd/display: change kzalloc to kcalloc in dml1_validate() Ethan Carter Edwards
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-02-27 23:16 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening,
	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.

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c
index e3ba105034f83434c3e77d343ee267069d34d926..26becc4cb80408cb2778f6af62c7a1c497f06505 100644
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c
@@ -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();

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] drm/amd/display: change kzalloc to kcalloc in dml1_validate()
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
                   ` (2 preceding siblings ...)
  2025-02-27 23:16 ` [PATCH 3/4] drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() Ethan Carter Edwards
@ 2025-02-27 23:16 ` Ethan Carter Edwards
  2025-03-04 18:12 ` [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Rodrigo Siqueira
  2025-03-06 21:24 ` Alex Hung
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-02-27 23:16 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening,
	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.

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c
index 664302876019072a77b9330229f7fe8545787396..2a59cc61ed8c918a4b5beb1d90bf3a8f77fcdeb9 100644
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c
@@ -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

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...)
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
                   ` (3 preceding siblings ...)
  2025-02-27 23:16 ` [PATCH 4/4] drm/amd/display: change kzalloc to kcalloc in dml1_validate() Ethan Carter Edwards
@ 2025-03-04 18:12 ` Rodrigo Siqueira
  2025-03-06 21:24 ` Alex Hung
  5 siblings, 0 replies; 7+ messages in thread
From: Rodrigo Siqueira @ 2025-03-04 18:12 UTC (permalink / raw)
  To: Ethan Carter Edwards, Alex Hung, Aurabindo Pillai, Roman Li
  Cc: Harry Wentland, Leo Li, Alex Deucher, Christian König,
	David Airlie, Simona Vetter, amd-gfx, dri-devel, linux-kernel,
	linux-hardening

On 02/27, Ethan Carter Edwards wrote:
> 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.
> 
> Link: https://github.com/KSPP/linux/issues/162
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> 
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
> ---
> 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,
> -- 
> Ethan Carter Edwards <ethan@ethancedwards.com>
>

Hi,

This series LGTM,

Reviewed-by: Rodrigo Siqueira <siqueira@igalia.com>

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

-- 
Rodrigo Siqueira

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...)
  2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
                   ` (4 preceding siblings ...)
  2025-03-04 18:12 ` [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Rodrigo Siqueira
@ 2025-03-06 21:24 ` Alex Hung
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Hung @ 2025-03-06 21:24 UTC (permalink / raw)
  To: Ethan Carter Edwards, Harry Wentland, Leo Li, Rodrigo Siqueira,
	Alex Deucher, Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening

This series LGTM too.

Reviewed-by: Alex Hung <alex.hung@amd.com>

On 2/27/25 16:16, Ethan Carter Edwards wrote:
> 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.
> 
> Link: https://github.com/KSPP/linux/issues/162
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> 
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
> ---
> 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,


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-03-06 21:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 23:16 [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Ethan Carter Edwards
2025-02-27 23:16 ` [PATCH 1/4] drm/amd/display: change kzalloc to kcalloc in dcn30_validate_bandwidth() Ethan Carter Edwards
2025-02-27 23:16 ` [PATCH 2/4] drm/amd/display: change kzalloc to kcalloc in dcn31_validate_bandwidth() Ethan Carter Edwards
2025-02-27 23:16 ` [PATCH 3/4] drm/amd/display: change kzalloc to kcalloc in dcn314_validate_bandwidth() Ethan Carter Edwards
2025-02-27 23:16 ` [PATCH 4/4] drm/amd/display: change kzalloc to kcalloc in dml1_validate() Ethan Carter Edwards
2025-03-04 18:12 ` [PATCH 0/4] drm/amd/display: move from kzalloc(size * nr, ...) to kcalloc(nr, size, ...) Rodrigo Siqueira
2025-03-06 21:24 ` Alex Hung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox