On Tue, 23 Sep 2025, Rahul Kumar <[email protected]> wrote:
> Documentation/process/deprecated.rst recommends against the use of
> kmalloc with dynamic size calculations due to the risk of overflow and
> smaller allocation being made than the caller was expecting.
>
> Replace kmalloc() with kmalloc_array() in drivers/gpu/drm/tiny/repaper.c
> to make the intended allocation size clearer and avoid potential overflow
> issues.
>
> Signed-off-by: Rahul Kumar <[email protected]>
> ---
>  drivers/gpu/drm/tiny/repaper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
> index 5c3b51eb0a97..4d439a2d973a 100644
> --- a/drivers/gpu/drm/tiny/repaper.c
> +++ b/drivers/gpu/drm/tiny/repaper.c
> @@ -535,7 +535,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
>       DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>                 epd->factored_stage_time);
>  
> -     buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
> +     buf = kmalloc_array(fb->width, fb->height / 8, GFP_KERNEL);

That's just not the same thing, though.

BR,
Jani.

>       if (!buf) {
>               ret = -ENOMEM;
>               goto out_exit;

-- 
Jani Nikula, Intel

Reply via email to