* [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc()
@ 2025-09-23 8:51 Mehdi Ben Hadj Khelifa
2025-10-04 16:13 ` Ruben Wauters
2025-10-07 7:45 ` Thomas Zimmermann
0 siblings, 2 replies; 4+ messages in thread
From: Mehdi Ben Hadj Khelifa @ 2025-09-23 8:51 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, airlied, simona, mingo,
tglx, mehdi.benhadjkhelifa, jfalempe, dri-devel, linux-kernel,
linux-kernel-mentees, skhan, david.hunter.linux, rubenru09
Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
calculation inside kmalloc is dynamic 'width * height' to avoid
overflow.
Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
---
Changelog:
Changes since v1:
- Use of width as element count and height as size of element to
eliminate the mentionned calculation and overflow issues.
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..8898dc9393fb 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(width, height, GFP_KERNEL);
if (!buf)
return 0;
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc()
2025-09-23 8:51 [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc() Mehdi Ben Hadj Khelifa
@ 2025-10-04 16:13 ` Ruben Wauters
2025-10-07 7:45 ` Thomas Zimmermann
1 sibling, 0 replies; 4+ messages in thread
From: Ruben Wauters @ 2025-10-04 16:13 UTC (permalink / raw)
To: Mehdi Ben Hadj Khelifa, maarten.lankhorst, mripard, tzimmermann,
airlied, simona, mingo, tglx, jfalempe, dri-devel, linux-kernel,
linux-kernel-mentees, skhan, david.hunter.linux
On Tue, 2025-09-23 at 09:51 +0100, Mehdi Ben Hadj Khelifa wrote:
> Replace kmalloc with kmalloc array in drm/gud/gud_pipe.c since the
> calculation inside kmalloc is dynamic 'width * height' to avoid
> overflow.
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
Acked-by: Ruben Wauters <rubenru09@aol.com>
> ---
> Changelog:
>
> Changes since v1:
> - Use of width as element count and height as size of element to
> eliminate the mentionned calculation and overflow issues.
>
> 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..8898dc9393fb 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(width, height, GFP_KERNEL);
> if (!buf)
> return 0;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc()
2025-09-23 8:51 [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc() Mehdi Ben Hadj Khelifa
2025-10-04 16:13 ` Ruben Wauters
@ 2025-10-07 7:45 ` Thomas Zimmermann
2025-10-07 8:07 ` Mehdi Ben Hadj Khelifa
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Zimmermann @ 2025-10-07 7:45 UTC (permalink / raw)
To: Mehdi Ben Hadj Khelifa, maarten.lankhorst, mripard, airlied,
simona, mingo, tglx, jfalempe, dri-devel, linux-kernel,
linux-kernel-mentees, skhan, david.hunter.linux, rubenru09
Hi
Am 23.09.25 um 10:51 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' to avoid
> overflow.
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
> ---
> Changelog:
>
> Changes since v1:
> - Use of width as element count and height as size of element to
> eliminate the mentionned calculation and overflow issues.
>
> 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..8898dc9393fb 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(width, height, GFP_KERNEL);
One nitpick here: the first parameter is the number of elements and the
second parameter is the size of an individual element. [1] So the
arguments 'width' and 'height' should be reversed. Please resubmit.
Best regards
Thomas
[1]
https://elixir.bootlin.com/linux/v6.17.1/source/tools/include/linux/slab.h#L15
> 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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc()
2025-10-07 7:45 ` Thomas Zimmermann
@ 2025-10-07 8:07 ` Mehdi Ben Hadj Khelifa
0 siblings, 0 replies; 4+ messages in thread
From: Mehdi Ben Hadj Khelifa @ 2025-10-07 8:07 UTC (permalink / raw)
To: Thomas Zimmermann, maarten.lankhorst, mripard, airlied, simona,
mingo, tglx, jfalempe, dri-devel, linux-kernel,
linux-kernel-mentees, skhan, david.hunter.linux, rubenru09
On 10/7/25 8:45 AM, Thomas Zimmermann wrote:
> Hi
>
> Am 23.09.25 um 10:51 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' to avoid
>> overflow.
>>
>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>> ---
>> Changelog:
>>
>> Changes since v1:
>> - Use of width as element count and height as size of element to
>> eliminate the mentionned calculation and overflow issues.
>>
>> 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..8898dc9393fb 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(width, height, GFP_KERNEL);
>
> One nitpick here: the first parameter is the number of elements and the
> second parameter is the size of an individual element. [1] So the
> arguments 'width' and 'height' should be reversed. Please resubmit.
>
Understood,I will be sending v3 shortly.
> Best regards
> Thomas
>
Best Regards,
Mehdi
> [1] https://elixir.bootlin.com/linux/v6.17.1/source/tools/include/linux/
> slab.h#L15
>
>> if (!buf)
>> return 0;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-07 8:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 8:51 [PATCH v2] drm/gud: Use kmalloc_array() instead of kmalloc() Mehdi Ben Hadj Khelifa
2025-10-04 16:13 ` Ruben Wauters
2025-10-07 7:45 ` Thomas Zimmermann
2025-10-07 8:07 ` Mehdi Ben Hadj Khelifa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox