public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] drm/tiny: Use kmalloc_array() instead of kmalloc()
@ 2025-10-19 15:12 Mehdi Ben Hadj Khelifa
  2025-10-19 14:34 ` Greg KH
  0 siblings, 1 reply; 14+ messages in thread
From: Mehdi Ben Hadj Khelifa @ 2025-10-19 15:12 UTC (permalink / raw)
  To: lanzano.alex, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona
  Cc: dri-devel, linux-kernel, skhan, david.hunter.linux, khalid,
	linux-kernel-mentees, Mehdi Ben Hadj Khelifa

Replace kmalloc() with kmalloc_array() to correctly
handle array allocations and benefit from built-in overflow checking[1].

[1]:https://docs.kernel.org/process/deprecated.html

Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
---
 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 4824f863fdba..290132c24ff9 100644
--- a/drivers/gpu/drm/tiny/repaper.c
+++ b/drivers/gpu/drm/tiny/repaper.c
@@ -534,7 +534,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, const struct iosys_map *
 	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->height / 8, fb->width, GFP_KERNEL);
 	if (!buf) {
 		ret = -ENOMEM;
 		goto out_exit;
-- 
2.51.1.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH] drm/tiny: Use kmalloc_array() instead of kmalloc()
@ 2025-09-23 11:00 Rahul Kumar
  2025-09-23 13:51 ` Jani Nikula
  0 siblings, 1 reply; 14+ messages in thread
From: Rahul Kumar @ 2025-09-23 11:00 UTC (permalink / raw)
  To: lanzano.alex, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona
  Cc: dri-devel, linux-kernel, linux-kernel-mentees, skhan, rk0006818

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 <rk0006818@gmail.com>
---
 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);
 	if (!buf) {
 		ret = -ENOMEM;
 		goto out_exit;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-10-20 21:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-19 15:12 [PATCH] drm/tiny: Use kmalloc_array() instead of kmalloc() Mehdi Ben Hadj Khelifa
2025-10-19 14:34 ` Greg KH
2025-10-19 14:47   ` Thomas Zimmermann
2025-10-19 16:03     ` Mehdi Ben Hadj Khelifa
2025-10-20  9:50       ` Jani Nikula
2025-10-20 10:49         ` Thomas Zimmermann
2025-10-20 20:06         ` Shuah Khan
2025-10-20 21:11           ` Mehdi Ben Hadj Khelifa
2025-10-20 20:22             ` Shuah Khan
2025-10-20 20:22             ` Shuah Khan
2025-10-20 22:00               ` Mehdi Ben Hadj Khelifa
  -- strict thread matches above, loose matches on Subject: below --
2025-09-23 11:00 Rahul Kumar
2025-09-23 13:51 ` Jani Nikula
2025-09-24  6:07   ` Rahul Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox