mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
drm/vc4: fix krealloc() memory leak
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: 6d45c81d22 ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Link: https://patch.msgid.link/20260606123817.37222-1-grandmaster@al2klimov.de
This commit is contained in:
parent
f329e8325e
commit
5d563a5da8
|
|
@ -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++;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user