drm/tiny: Use kmalloc_array() instead of kmalloc()
PATCH 1/1 drm/tiny: Use kmalloc_array() instead of kmalloc()
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.
--- drivers/gpu/drm/tiny/repaper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/repaper.c +1 -1
@@ -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 );if (!buf) { ret = -ENOMEM ; goto out_exit;
Signature · 1 line
2.43.0
Quoted 18 lines · Rahul Kumar
Documentation/process/deprecated.rstrecommends 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()withkmalloc_array()indrivers/gpu/drm/tiny/repaper.cto 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(-)drivers/gpu/drm/tiny/repaper.c +0
-0
drivers/gpu/drm/tiny/repaper.c static int repaper_fb_dirty(struct drm_framebuffer *fb, · line 538
Quoted 5 lines
drivers/gpu/drm/tiny/repaper.c +1
-1@@ -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.
Quoted 3 lines
drivers/gpu/drm/tiny/repaper.c +0
-0if (!buf) { ret = -ENOMEM ; goto out_exit;
Signature · 1 line
Jani Nikula, Intel
Quoted 23 lines · Jani Nikula
Quoted 21 lines · Rahul Kumar
Documentation/process/deprecated.rstrecommends 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()withkmalloc_array()indrivers/gpu/drm/tiny/repaper.cto 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(-)drivers/gpu/drm/tiny/repaper.c +0
-0@@ -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);
Quoted 5 lines
drivers/gpu/drm/tiny/repaper.c static int repaper_fb_dirty(struct drm_framebuffer *fb, · line 538
Quoted 2 lines
drivers/gpu/drm/tiny/repaper.c +1
-1- 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.
Thanks Jani, you are right. My change made the allocation size different from the original (width * height / 8). The current code is fine, so I will not change it.
Thanks,
Rahul
Quoted 9 lines
BR,
Jani.drivers/gpu/drm/tiny/repaper.c static int repaper_fb_dirty(struct drm_framebuffer *fb, · line 541
Quoted 3 lines
drivers/gpu/drm/tiny/repaper.c +0
-0if (!buf) { ret = -ENOMEM ; goto out_exit;--
Jani Nikula, Intel