Re: [PATCH] drm/vc4: fix krealloc() memory leak
From: Maíra Canal
Date: Thu May 28 2026 - 15:02:01 EST
Hi Alexander,
On 28/05/26 15:54, Alexander A. Klimov wrote:
On 5/28/26 20:17, Maíra Canal wrote:
Hi Alexander,
LGTM, but a small styling nit:
On 26/05/26 15:41, 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;
Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@xxxxxxxxxxxx>
---
drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------
1 file changed, 6 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..af48758592f9 100644
--- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
+++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
@@ -291,14 +291,14 @@ 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;
Declare the variable here.
Strange...
It comes already directly after num_uniforms, doesn't it?
Yeah, it does. However, usually, we declare the variables and then we
proceed to the functions. Check, for example, the function
record_texture_sample() in vc4.
Best regards,
- Maíra
At least when I apply my patch to Linus' master.