From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: media: meson: vdec: Handle kthread failure and free codec state
Date: Thu, 04 Jun 2026 15:48:46 +1000 [thread overview]
Message-ID: <review-patch3-20260530094326.11892-4-linux.amoon@gmail.com> (raw)
In-Reply-To: <20260530094326.11892-4-linux.amoon@gmail.com>
Patch Review
**Bug — double free of `sess->priv`:**
```c
err_cleanup:
vdec_free_canvas(sess);
vdec_poweroff(sess);
if (codec_ops && codec_ops->stop && sess->priv) {
codec_ops->stop(sess);
kfree(sess->priv);
sess->priv = NULL;
}
```
`vdec_poweroff()` calls `vdec_ops->stop(sess)` (i.e., `vdec_1_stop` or `vdec_hevc_stop`). Looking at the existing code in `vdec_1.c:160-162`:
```c
if (sess->priv)
codec_ops->stop(sess);
```
So `vdec_poweroff()` → `vdec_ops->stop()` already calls `codec_ops->stop()`. Then the error path calls `codec_ops->stop(sess)` again. The codec stop functions (e.g., `codec_h264_stop`, `codec_vp9_stop`) free internal DMA allocations tracked in `sess->priv` — calling it twice leads to double-free of those DMA buffers. After that, the explicit `kfree(sess->priv)` is yet another issue: the codec's own stop function does NOT free `sess->priv` itself (the normal teardown path in `vdec_stop_streaming` does `kfree(sess->priv)`), but this second `codec_ops->stop()` will operate on already-freed internal state.
**The fix should be:** remove the `codec_ops->stop()` call from `err_cleanup` since `vdec_poweroff()` already handles it, and just do:
```c
err_cleanup:
vdec_poweroff(sess);
vdec_free_canvas(sess);
kfree(sess->priv);
sess->priv = NULL;
```
**Also note:** `vdec_free_canvas()` is called before `vdec_poweroff()`, but in `vdec_stop_streaming()` the order is `vdec_poweroff()` then `vdec_free_canvas()`. The ordering should be consistent — power off first, then free resources.
**Good:** Adding `IS_ERR()` check for `kthread_run()` is a genuine fix.
**Good:** The `sess->vififo_vaddr = NULL` guard and the `vififo_vaddr` check in `vdec_stop_streaming` are defensive but reasonable.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-06-04 5:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 9:42 [PATCH v6 0/8] media: meson: Fix memory leak in error path in vdec Anand Moon
2026-05-30 9:42 ` [PATCH v6 1/8] media: meson: vdec: Fix memory leaks and lifetime of m2m device Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 2/8] media: meson: vdec: Fix concurrent STREAMON / STREAMOFF race conditions Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 3/8] media: meson: vdec: Handle kthread failure and free codec state Anand Moon
2026-06-04 5:48 ` Claude Code Review Bot [this message]
2026-05-30 9:42 ` [PATCH v6 4/8] media: meson: vdec: Condition buffer flushing on queue type in start_streaming Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 5/8] media: meson: vdec: Cancel esparser work during teardown Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 6/8] media: meson: vdec: Configure DMA mask and segment size in probe Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 7/8] media: meson: vdec: Fix NULL pointer dereference in ISR handlers Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-05-30 9:42 ` [PATCH v6 8/8] gpu: drm: meson: Fix DMA max segment size for DMABUF imports Anand Moon
2026-06-04 5:48 ` Claude review: " Claude Code Review Bot
2026-06-04 5:48 ` Claude review: media: meson: Fix memory leak in error path in vdec Claude Code Review Bot
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-patch3-20260530094326.11892-4-linux.amoon@gmail.com \
--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