From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: misc: fastrpc: Allocate entire reserved memory for Audio PD in probe
Date: Sat, 16 May 2026 09:09:54 +1000 [thread overview]
Message-ID: <review-patch4-20260515124217.20723-5-jianping.li@oss.qualcomm.com> (raw)
In-Reply-To: <20260515124217.20723-5-jianping.li@oss.qualcomm.com>
Patch Review
**Verdict: Needs fixes — two memory leaks in probe error paths, and a logic issue with `audio_init_mem` reset.**
**Bug 1: Memory leak on kzalloc failure in probe**
```c
+ if (domain_id == ADSP_DOMAIN_ID) {
+ data->remote_heap =
+ kzalloc_obj(*data->remote_heap, GFP_KERNEL);
+ if (!data->remote_heap)
+ return -ENOMEM;
```
At this point, `data` has already been allocated (line ~2373). The bare `return -ENOMEM` leaks `data`. This should be `goto err_free_data` or equivalent. Also, note that `kzalloc_obj(*data->remote_heap)` without explicit `GFP_KERNEL` would be equivalent since `default_gfp()` defaults to `GFP_KERNEL`.
**Bug 2: Memory leak on SCM failure in probe**
If `qcom_scm_assign_mem()` fails after `data->remote_heap` was allocated:
```c
err = qcom_scm_assign_mem(res.start, resource_size(&res), &src_perms,
data->vmperms, data->vmcount);
if (err)
goto err_free_data;
```
The `err_free_data` label only does `kfree(data)` — it does not free `data->remote_heap`. This leaks the remote_heap allocation.
**Issue 3: Unconditional `audio_init_mem = false` in err_invoke**
```c
err_invoke:
- if (fl->cctx->vmcount && scm_done) { ... }
-err_map:
- fastrpc_buf_free(fl->cctx->remote_heap);
- fl->cctx->remote_heap = NULL;
-err_name:
+ fl->cctx->audio_init_mem = false;
```
If two concurrent callers enter `fastrpc_init_create_static_process()`, the first one sets `audio_init_mem = true` and succeeds. The second caller takes the `else` branch (pageslen=0, pages=0). If the second caller's invoke fails, `audio_init_mem` is unconditionally reset to `false`. A subsequent third caller would then re-send the memory information to the DSP, which the DSP may have already received from the first call. The reset should be conditional:
```c
err_invoke:
if (inbuf.pageslen)
fl->cctx->audio_init_mem = false;
```
**Style nit: Inconsistent cctx usage**
The patch adds `struct fastrpc_channel_ctx *cctx = fl->cctx;` but then mixes `fl->cctx->` and `cctx->` in the same code block:
```c
+ spin_lock_irqsave(&cctx->lock, flags);
+ if (!fl->cctx->audio_init_mem) {
+ if (!fl->cctx->remote_heap ||
```
Should consistently use `cctx->` throughout.
**Observation on remove path**
The remove path correctly uses `kfree()` instead of `fastrpc_buf_free()` since the buffer was allocated with `kzalloc_obj` (not DMA coherent allocation). However, if `qcom_scm_assign_mem` fails during remove, the remote_heap struct is never freed:
```c
+ err = qcom_scm_assign_mem(cctx->remote_heap->dma_addr,
+ cctx->remote_heap->size, &src_perms,
+ &dst_perms, 1);
+ if (!err)
+ kfree(cctx->remote_heap);
```
If the SCM call fails during teardown, there's not much that can be done, but a `dev_err()` log would be helpful for debugging, and the memory should arguably be freed anyway since the channel is shutting down (the SCM failure means the memory ownership is in a bad state, but leaking the tracking struct doesn't help).
Also: if `cctx->vmcount` is 0 but `cctx->remote_heap` is non-NULL, the entire block is skipped and `remote_heap` is leaked. This could happen if the ADSP domain has reserved-memory in DT but no `qcom,vmids`.
---
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-15 23:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 12:42 [PATCH v5 0/5] misc: fastrpc: Add missing bug fixes Jianping Li
2026-05-15 12:42 ` [PATCH v5 1/5] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool Jianping Li
2026-05-15 13:33 ` Dmitry Baryshkov
2026-05-15 23:09 ` Claude review: " Claude Code Review Bot
2026-05-15 12:42 ` [PATCH v5 2/5] misc: fastrpc: Remove buffer from list prior to unmap operation Jianping Li
2026-05-15 13:36 ` Dmitry Baryshkov
2026-05-15 23:09 ` Claude review: " Claude Code Review Bot
2026-05-15 12:42 ` [PATCH v5 3/5] misc: fastrpc: Fail Audio PD init when reserved memory is missing Jianping Li
2026-05-15 13:37 ` Dmitry Baryshkov
2026-05-15 23:09 ` Claude review: " Claude Code Review Bot
2026-05-15 12:42 ` [PATCH v5 4/5] misc: fastrpc: Allocate entire reserved memory for Audio PD in probe Jianping Li
2026-05-15 13:38 ` Dmitry Baryshkov
2026-05-15 23:09 ` Claude Code Review Bot [this message]
2026-05-15 12:42 ` [PATCH v5 5/5] misc: fastrpc: Allow fastrpc_buf_free() to accept NULL Jianping Li
2026-05-15 23:09 ` Claude review: " Claude Code Review Bot
2026-05-15 23:09 ` Claude review: misc: fastrpc: Add missing bug fixes Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-04-09 6:26 [PATCH v4 0/4] " Jianping Li
2026-04-09 6:26 ` [PATCH v4 3/4] misc: fastrpc: Allocate entire reserved memory for Audio PD in probe Jianping Li
2026-04-12 1:44 ` Claude review: " 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-patch4-20260515124217.20723-5-jianping.li@oss.qualcomm.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