[PATCH v3] drm/gud: Use kmalloc_array() instead of kmalloc()

Mehdi Ben Hadj Khelifa posted 1 patch 2 months, 1 week ago
drivers/gpu/drm/gud/gud_pipe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v3] drm/gud: Use kmalloc_array() instead of kmalloc()
Posted by Mehdi Ben Hadj Khelifa 2 months, 1 week ago
Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
calculation inside kmalloc is dynamic 'width * height'

Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
---
Changelog:

Changes since v2:
-Reversed width and height in parameter order.
Link:https://lore.kernel.org/all/20250923085144.22582-1-mehdi.benhadjkhelifa@gmail.com/
Changes since v1:
- Use of width as element count and height as size of element to
eliminate the mentionned calculation and overflow issues.
Link:https://lore.kernel.org/all/20250922174416.226203-1-mehdi.benhadjkhelifa@gmail.com/
 drivers/gpu/drm/gud/gud_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
index 8d548d08f127..c32a798ccadf 100644
--- a/drivers/gpu/drm/gud/gud_pipe.c
+++ b/drivers/gpu/drm/gud/gud_pipe.c
@@ -70,7 +70,7 @@ static size_t gud_xrgb8888_to_r124(u8 *dst, const struct drm_format_info *format
 	height = drm_rect_height(rect);
 	len = drm_format_info_min_pitch(format, 0, width) * height;
 
-	buf = kmalloc(width * height, GFP_KERNEL);
+	buf = kmalloc_array(height, width, GFP_KERNEL);
 	if (!buf)
 		return 0;
 
-- 
2.51.0
Re: [PATCH v3] drm/gud: Use kmalloc_array() instead of kmalloc()
Posted by Thomas Zimmermann 2 months, 1 week ago

Am 07.10.25 um 10:32 schrieb Mehdi Ben Hadj Khelifa:
> Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
> calculation inside kmalloc is dynamic 'width * height'
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>

Applied to drm-misc-next.

> ---
> Changelog:
>
> Changes since v2:
> -Reversed width and height in parameter order.
> Link:https://lore.kernel.org/all/20250923085144.22582-1-mehdi.benhadjkhelifa@gmail.com/
> Changes since v1:
> - Use of width as element count and height as size of element to
> eliminate the mentionned calculation and overflow issues.
> Link:https://lore.kernel.org/all/20250922174416.226203-1-mehdi.benhadjkhelifa@gmail.com/
>   drivers/gpu/drm/gud/gud_pipe.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
> index 8d548d08f127..c32a798ccadf 100644
> --- a/drivers/gpu/drm/gud/gud_pipe.c
> +++ b/drivers/gpu/drm/gud/gud_pipe.c
> @@ -70,7 +70,7 @@ static size_t gud_xrgb8888_to_r124(u8 *dst, const struct drm_format_info *format
>   	height = drm_rect_height(rect);
>   	len = drm_format_info_min_pitch(format, 0, width) * height;
>   
> -	buf = kmalloc(width * height, GFP_KERNEL);
> +	buf = kmalloc_array(height, width, GFP_KERNEL);
>   	if (!buf)
>   		return 0;
>   

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
Re: [PATCH v3] drm/gud: Use kmalloc_array() instead of kmalloc()
Posted by Thomas Zimmermann 2 months, 1 week ago
Hi

Am 07.10.25 um 10:32 schrieb Mehdi Ben Hadj Khelifa:
> Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
> calculation inside kmalloc is dynamic 'width * height'
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

As Ruben already acked the previous patch, you should add such acks to 
any later patches. But no need to resend a new iteration now. I'll add 
Ruben's a-b when I merge the patch.

Best regards
Thomas

> ---
> Changelog:
>
> Changes since v2:
> -Reversed width and height in parameter order.
> Link:https://lore.kernel.org/all/20250923085144.22582-1-mehdi.benhadjkhelifa@gmail.com/
> Changes since v1:
> - Use of width as element count and height as size of element to
> eliminate the mentionned calculation and overflow issues.
> Link:https://lore.kernel.org/all/20250922174416.226203-1-mehdi.benhadjkhelifa@gmail.com/
>   drivers/gpu/drm/gud/gud_pipe.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
> index 8d548d08f127..c32a798ccadf 100644
> --- a/drivers/gpu/drm/gud/gud_pipe.c
> +++ b/drivers/gpu/drm/gud/gud_pipe.c
> @@ -70,7 +70,7 @@ static size_t gud_xrgb8888_to_r124(u8 *dst, const struct drm_format_info *format
>   	height = drm_rect_height(rect);
>   	len = drm_format_info_min_pitch(format, 0, width) * height;
>   
> -	buf = kmalloc(width * height, GFP_KERNEL);
> +	buf = kmalloc_array(height, width, GFP_KERNEL);
>   	if (!buf)
>   		return 0;
>   

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
Re: [PATCH v3] drm/gud: Use kmalloc_array() instead of kmalloc()
Posted by Mehdi Ben Hadj Khelifa 2 months, 1 week ago
On 10/7/25 9:58 AM, Thomas Zimmermann wrote:
> Hi
> 
> Am 07.10.25 um 10:32 schrieb Mehdi Ben Hadj Khelifa:
>> Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
>> calculation inside kmalloc is dynamic 'width * height'
>>
>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
> 
> Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
> As Ruben already acked the previous patch, you should add such acks to 
> any later patches. But no need to resend a new iteration now. I'll add 
> Ruben's a-b when I merge the patch.

ack,I forgot about that. Thanks for the heads-up.We'll do next time!

> Best regards
> Thomas

Best Regards,
Mehdi Ben Hadj Khelifa

>> ---
>> Changelog:
>>
>> Changes since v2:
>> -Reversed width and height in parameter order.
>> Link:https://lore.kernel.org/all/20250923085144.22582-1- 
>> mehdi.benhadjkhelifa@gmail.com/
>> Changes since v1:
>> - Use of width as element count and height as size of element to
>> eliminate the mentionned calculation and overflow issues.
>> Link:https://lore.kernel.org/all/20250922174416.226203-1- 
>> mehdi.benhadjkhelifa@gmail.com/
>>   drivers/gpu/drm/gud/gud_pipe.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/ 
>> gud_pipe.c
>> index 8d548d08f127..c32a798ccadf 100644
>> --- a/drivers/gpu/drm/gud/gud_pipe.c
>> +++ b/drivers/gpu/drm/gud/gud_pipe.c
>> @@ -70,7 +70,7 @@ static size_t gud_xrgb8888_to_r124(u8 *dst, const 
>> struct drm_format_info *format
>>       height = drm_rect_height(rect);
>>       len = drm_format_info_min_pitch(format, 0, width) * height;
>> -    buf = kmalloc(width * height, GFP_KERNEL);
>> +    buf = kmalloc_array(height, width, GFP_KERNEL);
>>       if (!buf)
>>           return 0;
>