From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/amdgpu: Fix resource leaks
Date: Fri, 27 Feb 2026 13:15:07 +1000 [thread overview]
Message-ID: <review-patch1-20260225145154.14168-1-ethantidmore06@gmail.com> (raw)
In-Reply-To: <20260225145154.14168-1-ethantidmore06@gmail.com>
Patch Review
**The Smatch warning is valid.** There are real `ioremap()` leaks on early error returns in `amdgpu_device_init()`. However, `devm_ioremap()` is the wrong fix for the following reasons:
**1. Use-after-free via DRM device release path**
The PCI removal sequence is:
```
amdgpu_pci_remove()
→ drm_dev_unplug()
→ amdgpu_driver_unload_kms() → amdgpu_device_fini_hw()
return
devres_release_all() ← devm_ioremap mapping freed HERE
...
[later, when last DRM fd is closed]
amdgpu_driver_release_kms()
→ amdgpu_device_fini_sw()
→ amdgpu_device_ip_fini() ← uses stale adev->rmmio!
```
`amdgpu_device_fini_sw()` is called from the DRM `.release` callback (`amdgpu_driver_release_kms` at `amdgpu_kms.c:1615`), which fires when the last DRM fd reference drops. If userspace still has the device open, this runs **after** `devres_release_all()` has already freed the `devm_ioremap` mapping. At that point `adev->rmmio` is a dangling pointer.
**2. Removal of `adev->rmmio = NULL` breaks guards**
The patch removes both:
```c
- iounmap(adev->rmmio);
- adev->rmmio = NULL;
```
But `adev->rmmio == NULL` is used as a validity check elsewhere, e.g., in `amdgpu_kms.c:91`:
```c
if (adev->rmmio == NULL)
return;
```
After this patch, `adev->rmmio` is never NULLed, so this guard becomes ineffective even though the mapping may already have been freed by devm.
**3. Removal of `drm_dev_enter()` guard breaks hotplug coordination**
The removed code in `amdgpu_device_fini_sw()`:
```c
- if (drm_dev_enter(adev_to_drm(adev), &idx)) {
- iounmap(adev->rmmio);
- adev->rmmio = NULL;
- drm_dev_exit(idx);
- }
```
This `drm_dev_enter()` guard coordinates with `amdgpu_device_unmap_mmio()` (the hotplug path). When the device is unplugged, `drm_dev_enter()` fails and the `iounmap` is skipped because `amdgpu_device_unmap_mmio()` already handled it. This careful coordination is lost with the patch.
**Suggested fix:** Instead of `devm_ioremap()`, the error paths in `amdgpu_device_init()` should be fixed with proper `goto` cleanup labels that call `iounmap(adev->rmmio)`. This addresses the Smatch warning without changing the resource lifetime semantics. Alternatively, if `devm_ioremap` is desired, the entire teardown logic across `fini_hw` / `fini_sw` / `unmap_mmio` needs to be reworked to ensure `adev->rmmio` is never accessed after the PCI driver unbinds, and `adev->rmmio` must be set to NULL when devm will handle the unmap.
---
Generated by Claude Code Patch Reviewer
prev parent reply other threads:[~2026-02-27 3:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 14:51 [PATCH v2] drm/amdgpu: Fix resource leaks Ethan Tidmore
2026-02-27 3:15 ` Claude review: " Claude Code Review Bot
2026-02-27 3:15 ` 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-20260225145154.14168-1-ethantidmore06@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