From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/vc4: fix krealloc() memory leak
Date: Wed, 27 May 2026 14:21:19 +1000 [thread overview]
Message-ID: <review-patch1-20260526184105.18962-5-grandmaster@al2klimov.de> (raw)
In-Reply-To: <20260526184105.18962-5-grandmaster@al2klimov.de>
Patch Review
**Correctness: Good.** The fix correctly addresses a real memory leak. In the original code:
```c
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)
return false;
```
If `krealloc()` returns NULL, the original allocation pointed to by `uniform_addr_offsets` is leaked because the pointer is overwritten before the NULL check. The caller chain eventually calls `kfree(validated_shader->uniform_addr_offsets)` in the cleanup paths (`vc4_validate_shaders.c:951`, `vc4_bo.c:176`, `vc4_bo.c:585`), but since `uniform_addr_offsets` is now NULL, the free is a no-op and the original memory leaks.
**Fix approach:** The fix uses a `void *mem` temporary variable and only assigns to `validated_shader->uniform_addr_offsets` after confirming non-NULL:
```c
void *mem = krealloc(validated_shader->uniform_addr_offsets,
(o + 1) *
sizeof(*validated_shader->uniform_addr_offsets),
GFP_KERNEL);
if (!mem)
return false;
validated_shader->uniform_addr_offsets = mem;
```
This preserves the original pointer on failure so the existing cleanup paths can properly free it.
**Minor style observation:** The temporary is typed `void *` rather than `uint32_t *` (the actual type of `uniform_addr_offsets` as seen in `vc4_drv.h:858`). This works correctly since C allows implicit conversion from `void *`, and it's idiomatic for krealloc wrappers. However, using `uint32_t *mem` would be slightly more type-safe and avoid the implicit cast. This is a matter of taste and not a blocker — the series likely uses `void *` consistently across all patches for the same krealloc pattern.
**Fixes tag:** Correctly references commit `6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")` which introduced this code.
**Scope:** The change is minimal and precisely scoped — only the 6 lines around the krealloc call are modified, with no functional change on the success path.
**Recommendation: Patch is correct. Apply as-is.**
---
Generated by Claude Code Patch Reviewer
prev parent reply other threads:[~2026-05-27 4:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260526184105.18962-1-grandmaster@al2klimov.de>
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
2026-05-27 4:21 ` Claude review: " Claude Code Review Bot
2026-05-27 4:21 ` Claude Code Review Bot [this message]
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=review-patch1-20260526184105.18962-5-grandmaster@al2klimov.de \
--to=claude-review@example.com \
--cc=dri-devel-reviews@example.com \
/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