* [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc()
@ 2025-09-14 7:38 James Flowers
2025-09-17 9:33 ` Javier Martinez Canillas
2025-09-17 10:49 ` Javier Martinez Canillas
0 siblings, 2 replies; 3+ messages in thread
From: James Flowers @ 2025-09-14 7:38 UTC (permalink / raw)
To: javierm, maarten.lankhorst, mripard, tzimmermann, airlied, simona,
skhan
Cc: James Flowers, dri-devel, linux-kernel, linux-kernel-mentees
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.
kmalloc_array avoids this issue.
Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
---
Note: this has only been compile tested.
drivers/gpu/drm/solomon/ssd130x.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c
index eec43d1a5595..8368f0ffbe1e 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -1498,7 +1498,7 @@ static int ssd130x_crtc_atomic_check(struct drm_crtc *crtc,
if (ret)
return ret;
- ssd130x_state->data_array = kmalloc(ssd130x->width * pages, GFP_KERNEL);
+ ssd130x_state->data_array = kmalloc_array(ssd130x->width, pages, GFP_KERNEL);
if (!ssd130x_state->data_array)
return -ENOMEM;
@@ -1519,7 +1519,7 @@ static int ssd132x_crtc_atomic_check(struct drm_crtc *crtc,
if (ret)
return ret;
- ssd130x_state->data_array = kmalloc(columns * ssd130x->height, GFP_KERNEL);
+ ssd130x_state->data_array = kmalloc_array(columns, ssd130x->height, GFP_KERNEL);
if (!ssd130x_state->data_array)
return -ENOMEM;
@@ -1546,7 +1546,7 @@ static int ssd133x_crtc_atomic_check(struct drm_crtc *crtc,
pitch = drm_format_info_min_pitch(fi, 0, ssd130x->width);
- ssd130x_state->data_array = kmalloc(pitch * ssd130x->height, GFP_KERNEL);
+ ssd130x_state->data_array = kmalloc_array(pitch, ssd130x->height, GFP_KERNEL);
if (!ssd130x_state->data_array)
return -ENOMEM;
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc()
2025-09-14 7:38 [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc() James Flowers
@ 2025-09-17 9:33 ` Javier Martinez Canillas
2025-09-17 10:49 ` Javier Martinez Canillas
1 sibling, 0 replies; 3+ messages in thread
From: Javier Martinez Canillas @ 2025-09-17 9:33 UTC (permalink / raw)
To: James Flowers, maarten.lankhorst, mripard, tzimmermann, airlied,
simona, skhan
Cc: James Flowers, dri-devel, linux-kernel, linux-kernel-mentees
James Flowers <bold.zone2373@fastmail.com> writes:
Hello James,
Thanks for the patch.
> 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.
> kmalloc_array avoids this issue.
>
> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc()
2025-09-14 7:38 [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc() James Flowers
2025-09-17 9:33 ` Javier Martinez Canillas
@ 2025-09-17 10:49 ` Javier Martinez Canillas
1 sibling, 0 replies; 3+ messages in thread
From: Javier Martinez Canillas @ 2025-09-17 10:49 UTC (permalink / raw)
To: James Flowers, maarten.lankhorst, mripard, tzimmermann, airlied,
simona, skhan
Cc: James Flowers, dri-devel, linux-kernel, linux-kernel-mentees
James Flowers <bold.zone2373@fastmail.com> writes:
> 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.
> kmalloc_array avoids this issue.
>
> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
> ---
Pushed to drm-misc (drm-misc-next). Thanks!
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-17 10:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-14 7:38 [PATCH] drm/ssd130x: Use kmalloc_array() instead of kmalloc() James Flowers
2025-09-17 9:33 ` Javier Martinez Canillas
2025-09-17 10:49 ` Javier Martinez Canillas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox