public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: Re: [PATCH] drm/amdgpu: Fix resource leaks
Date: Fri, 27 Feb 2026 14:17:10 +1000	[thread overview]
Message-ID: <review-patch1-202602251459.1jr0PuUf-lkp@intel.com> (raw)
In-Reply-To: <202602251459.1jr0PuUf-lkp@intel.com>

Patch Review

**The problem being fixed is real**: after `ioremap()` at line 4537, multiple error paths in `amdgpu_device_init()` return without calling `iounmap()`, and none of them go through `amdgpu_device_fini_sw()`. The Smatch warning is legitimate.

However, using `devm_ioremap()` is the wrong fix here for several reasons:

**1. Removal of `adev->rmmio = NULL` breaks hot-unplug guard logic**

In `amdgpu_device_unmap_mmio()`, the patch removes:
```c
-	iounmap(adev->rmmio);
-	adev->rmmio = NULL;
```

The `adev->rmmio = NULL` assignment is critical because it's checked in `amdgpu_driver_unload_kms()` (`amdgpu_kms.c:91`):
```c
if (adev->rmmio == NULL)
    return;
```

This guard prevents `amdgpu_device_fini_hw()` from running on an already-torn-down device during hot-unplug. With the patch applied, `adev->rmmio` is never set to NULL, so this guard never triggers, potentially causing use-after-free or double-teardown issues during PCI hot-unplug.

**2. Lifetime mismatch with hot-unplug path**

`amdgpu_device_unmap_mmio()` is called from `amdgpu_device_fini_hw()` when `pci_dev_is_disconnected()` is true (line 4937-4938). This is designed to immediately unmap MMIO when the PCI device disappears, so accesses to the now-gone hardware stop immediately. With `devm_ioremap()`, the unmap is deferred to device release time, meaning `adev->rmmio` remains a valid pointer to an ioremap'd region for a physically absent device — the register space behind it is gone. While `no_hw_access` flag guards most register accesses, the explicit unmap provided a second safety net.

**3. Removal of `drm_dev_enter()` guarded cleanup in `amdgpu_device_fini_sw()` is wrong**

The patch removes:
```c
-	if (drm_dev_enter(adev_to_drm(adev), &idx)) {
-
-		iounmap(adev->rmmio);
-		adev->rmmio = NULL;
-		drm_dev_exit(idx);
-	}
```

The `drm_dev_enter()` guard here is deliberate — it ensures the iounmap only happens when the DRM device is still accessible (i.e., NOT hot-unplugged). This two-site cleanup pattern (`amdgpu_device_unmap_mmio` for hot-unplug, `amdgpu_device_fini_sw` for normal shutdown) is intentional and correct. Removing it collapses two distinct lifecycle paths into "let devm handle it," which is the wrong abstraction for a driver with explicit hot-unplug support.

**4. devm cleanup ordering may conflict with other teardown**

`devm_ioremap()` resources are freed when the `struct device` is released. With `adev` allocated via `devm_drm_dev_alloc()`, the ordering between DRM device release and PCI device release can be subtle. Code in `amdgpu_device_fini_sw()` that runs *after* the removed iounmap block (e.g., `amdgpu_discovery_fini`, `amdgpu_pmu_fini`) may still need the MMIO mapping to be present (or at least deterministically know whether it is).

**Suggested alternative fix**: Instead of converting to `devm_ioremap()`, fix the actual error paths in `amdgpu_device_init()` by adding `iounmap(adev->rmmio)` before the failing returns after the ioremap, or consolidating the error cleanup through a goto label that performs the unmap. This is the more targeted and lower-risk fix for the Smatch warning.

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-02-27  4:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25  1:44 [PATCH] drm/amdgpu: Fix resource leaks Ethan Tidmore
2026-02-25  6:36 ` kernel test robot
2026-02-27  4:17   ` Claude review: " Claude Code Review Bot
2026-02-27  4:17   ` 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-202602251459.1jr0PuUf-lkp@intel.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