mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>,
	avier Martinez Canillas <javierm@redhat.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	khalid@kernel.org
Subject: Re: [PATCH] drm/ssd130x: Use kmalloc_array to prevent overflow of dynamic size calculation
Date: Thu, 2 Oct 2025 08:44:50 +0200	[thread overview]
Message-ID: <bfc90c7a-4ade-4bf0-88e3-86697e664e35@suse.de> (raw)
In-Reply-To: <20251002013312.67015-1-bhanuseshukumar@gmail.com>

Hi

Am 02.10.25 um 03:33 schrieb Bhanu Seshu Kumar Valluri:
> Use kmalloc_array to avoid potential overflow during dynamic size calculation
> inside kmalloc.
>
> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
> ---
>   Note:
>   Patch compiled successfully.
>   No functionality change is intended.
>
>   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);

The first parameter is the number of elements. The second parameter is 
the size of an individual element. So the arguments should be swapped. 
Same for the other changes.

I know it's nitpicking, but who knows what it'll be good for. Fun fact 
is that even kmalloc_array mixes up both parameters internally.

Best regards
Thomas


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

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)



  reply	other threads:[~2025-10-02  6:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02  1:33 Bhanu Seshu Kumar Valluri
2025-10-02  6:44 ` Thomas Zimmermann [this message]
2025-10-02  7:18   ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bfc90c7a-4ade-4bf0-88e3-86697e664e35@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=bhanuseshukumar@gmail.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=khalid@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®