From: "Maíra Canal" <mcanal@igalia.com>
To: "Alexander A. Klimov" <grandmaster@al2klimov.de>
Cc: Maxime Ripard <mripard@kernel.org>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Eric Anholt <eric@anholt.net>,
"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b"
<llvm@lists.linux.dev>
Subject: Re: [PATCH v3] drm/vc4: fix krealloc() memory leak
Date: Sat, 6 Jun 2026 10:32:17 -0300 [thread overview]
Message-ID: <fb731654-4666-460b-9c12-d07e24e7e659@igalia.com> (raw)
In-Reply-To: <20260606123817.37222-1-grandmaster@al2klimov.de>
On 06/06/26 09:38, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
>
> MEM = krealloc(MEM, SZ, GFP);
>
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
>
> TMP = krealloc(MEM, SZ, GFP);
> if (!TMP) return;
> MEM = TMP;
>
> While on it, use krealloc_array().
>
> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Best regards,
- Maíra
> ---
> v2: Declare the variable explicitly
> v2: Instead of void *, use u32 *
> v2: While on it, enhance variable name
> v3: Use krealloc_array()
>
> [✓] scripts/checkpatch.pl --strict
> [✓] allmodconfig compiled (i686, LLVM)
> [✓] localyesconfig booted (IBM T43)
>
> Note to myself: use --in-reply-to=e1edeadb7c161580a5cd5c7e642dc1b28db8ee86.camel@perches.com
>
> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> index d48cf76983c0..66502a6a4a8e 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> @@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
> {
> uint32_t o = validated_shader->num_uniform_addr_offsets;
> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
> + u32 *offsets;
>
> - validated_shader->uniform_addr_offsets =
> - krealloc(validated_shader->uniform_addr_offsets,
> - (o + 1) *
> - sizeof(*validated_shader->uniform_addr_offsets),
> - GFP_KERNEL);
> - if (!validated_shader->uniform_addr_offsets)
> + offsets = krealloc_array(validated_shader->uniform_addr_offsets,
> + o + 1,
> + sizeof(*validated_shader->uniform_addr_offsets),
> + GFP_KERNEL);
> + if (!offsets)
> return false;
>
> + validated_shader->uniform_addr_offsets = offsets;
> validated_shader->uniform_addr_offsets[o] = num_uniforms;
> validated_shader->num_uniform_addr_offsets++;
>
next prev parent reply other threads:[~2026-06-06 13:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/drivers/clps711x: " Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/timer-econet-en751221: " Alexander A. Klimov
2026-05-28 16:05 ` Caleb James DeLisle
2026-05-26 18:40 ` [PATCH] microblaze: CCF: " Alexander A. Klimov
2026-09-01 12:19 ` Michal Simek
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
2026-05-28 18:17 ` Maíra Canal
2026-05-28 18:54 ` Alexander A. Klimov
2026-05-28 19:01 ` Maíra Canal
2026-05-31 19:55 ` [PATCH v2] " Alexander A. Klimov
2026-06-01 3:34 ` Joe Perches
2026-06-06 12:38 ` [PATCH v3] " Alexander A. Klimov
2026-06-06 13:32 ` Maíra Canal [this message]
2026-06-09 18:49 ` Maíra Canal
2026-05-26 18:41 ` [PATCH] ibmvnic: " Alexander A. Klimov
2026-05-26 20:50 ` Nicolai Buchwitz
2026-05-27 17:22 ` Alexander A. Klimov
2026-05-26 22:41 ` [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Brian Masney
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=fb731654-4666-460b-9c12-d07e24e7e659@igalia.com \
--to=mcanal@igalia.com \
--cc=airlied@gmail.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric@anholt.net \
--cc=grandmaster@al2klimov.de \
--cc=justinstitt@google.com \
--cc=kernel-list@raspberrypi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=maarten.lankhorst@linux.intel.com \
--cc=morbo@google.com \
--cc=mripard@kernel.org \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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®