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

From: Ruben Wauters

Date: Sat Oct 04 2025 - 12:44:10 EST


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@xxxxxxxxx>

Acked-by: Ruben Wauters <rubenru09@xxxxxxx>

> ---
> 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;
>