linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: Use kcalloc() instead of kzalloc()
@ 2024-01-28  9:04 Lenko Donchev
  2024-02-21 23:04 ` Rodrigo Siqueira Jordao
  0 siblings, 1 reply; 2+ messages in thread
From: Lenko Donchev @ 2024-01-28  9:04 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, Pan, Xinhui, David Airlie, Daniel Vetter,
	amd-gfx, dri-devel, linux-kernel

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

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

Signed-off-by: Lenko Donchev <lenko.donchev@gmail.com>
---
 drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
index 5c9a30211c10..b67cd78e7c58 100644
--- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
+++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
@@ -164,7 +164,7 @@ static void dpcd_extend_address_range(
 	if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
 		*out_address = new_addr_range.start;
 		*out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
-		*out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
+		*out_data = kcalloc(*out_size, sizeof(**out_data), GFP_KERNEL);
 	}
 }
 
-- 
2.43.0


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

* Re: [PATCH] drm/amd/display: Use kcalloc() instead of kzalloc()
  2024-01-28  9:04 [PATCH] drm/amd/display: Use kcalloc() instead of kzalloc() Lenko Donchev
@ 2024-02-21 23:04 ` Rodrigo Siqueira Jordao
  0 siblings, 0 replies; 2+ messages in thread
From: Rodrigo Siqueira Jordao @ 2024-02-21 23:04 UTC (permalink / raw)
  To: Lenko Donchev
  Cc: Harry Wentland, Leo Li, Alex Deucher, Christian König, Pan,
	Xinhui, David Airlie, Daniel Vetter, amd-gfx, dri-devel,
	linux-kernel



On 1/28/24 02:04, Lenko Donchev wrote:
> We are trying to get rid of all multiplications from allocation
> functions to prevent integer overflows. Here the multiplication is
> obviously safe, but using kcalloc() is more appropriate and improves
> readability. This patch has no effect on runtime behavior.
> 
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> Link: https://github.com/KSPP/linux/issues/162
> 
> Signed-off-by: Lenko Donchev <lenko.donchev@gmail.com>
> ---
>   drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
> index 5c9a30211c10..b67cd78e7c58 100644
> --- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
> +++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
> @@ -164,7 +164,7 @@ static void dpcd_extend_address_range(
>   	if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
>   		*out_address = new_addr_range.start;
>   		*out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
> -		*out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
> +		*out_data = kcalloc(*out_size, sizeof(**out_data), GFP_KERNEL);
>   	}
>   }
>   

lgtm,

Reviewed-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>

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

end of thread, other threads:[~2024-02-21 23:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28  9:04 [PATCH] drm/amd/display: Use kcalloc() instead of kzalloc() Lenko Donchev
2024-02-21 23:04 ` Rodrigo Siqueira Jordao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).