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: drm/lima: call drm_mm_init() with a valid allocation range
Date: Thu, 04 Jun 2026 14:10:22 +1000	[thread overview]
Message-ID: <review-patch1-20260601-lima-alloc-fix-v1-1-16d3f3b7b780@axis.com> (raw)
In-Reply-To: <20260601-lima-alloc-fix-v1-1-16d3f3b7b780@axis.com>

Patch Review

**Bug analysis is correct.** `lima_vm_create()` at line 371 calls `drm_mm_init(&vm->mm, dev->va_start, dev->va_end - dev->va_start)` while both values are still 0, which triggers the `DRM_MM_BUG_ON` in `drm_mm_init()` when `DRM_DEBUG_MM` is enabled.

**Error handling bug — dlbu_cpu leak on mali450:**

After the patch, the initialization order becomes:

1. `va_start` / `va_end` setup
2. `dlbu_cpu` DMA allocation (mali450 only)
3. `lima_vm_create()`

If `lima_vm_create()` fails at step 3, the patch does:

```c
+	ldev->empty_vm = lima_vm_create(ldev);
+	if (!ldev->empty_vm) {
+		err = -ENOMEM;
+		goto err_out1;
+	}
```

But `goto err_out1` skips `err_out3` (which frees `dlbu_cpu`) and `err_out2` (which puts the VM). The cleanup labels are:

```c
err_out3:
	if (ldev->dlbu_cpu)
		dma_free_wc(ldev->dev, LIMA_PAGE_SIZE,
			    ldev->dlbu_cpu, ldev->dlbu_dma);
err_out2:
	lima_vm_put(ldev->empty_vm);
err_out1:
	lima_regulator_fini(ldev);
```

On mali450, `dlbu_cpu` was successfully allocated at step 2, so jumping to `err_out1` leaks that DMA allocation. The correct goto target should be `err_out3`, not `err_out1`. Going through `err_out3` will free `dlbu_cpu` if allocated, and `err_out2` is safe because `lima_vm_put()` handles NULL:

```c
static inline void lima_vm_put(struct lima_vm *vm)
{
	if (vm)
		kref_put(&vm->refcount, lima_vm_release);
}
```

**The existing `dlbu_cpu` failure goto is technically safe but sloppy.** The dlbu_cpu allocation failure path retains `goto err_out2`, which calls `lima_vm_put(ldev->empty_vm)` on a not-yet-created VM. This works only because `lima_vm_put()` has a NULL check and `ldev` is zero-initialized. It would be cleaner to change this to `goto err_out1`, though it's not a correctness bug.

**Behavioral change on mali450 — DLBU mapping in empty_vm:**

`lima_vm_create()` contains:
```c
if (dev->dlbu_cpu) {
	int err = lima_vm_map_page(
		vm, dev->dlbu_dma, LIMA_VA_RESERVE_DLBU);
```

In the original code, `dlbu_cpu` was NULL when `lima_vm_create()` ran, so this mapping was skipped for the `empty_vm`. After the patch, `dlbu_cpu` is allocated before `lima_vm_create()`, so the DLBU page is now mapped in the `empty_vm`. This is likely the correct behavior (and the original omission was an unintentional consequence of the wrong ordering), but the commit message does not mention this change.

**Suggested fix:** Change the `lima_vm_create()` failure goto from `err_out1` to `err_out3`:

```c
	ldev->empty_vm = lima_vm_create(ldev);
	if (!ldev->empty_vm) {
		err = -ENOMEM;
-		goto err_out1;
+		goto err_out3;
	}
```

And optionally clean up the dlbu_cpu failure goto:

```c
	if (!ldev->dlbu_cpu) {
		err = -ENOMEM;
-		goto err_out2;
+		goto err_out1;
	}
```

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-06-04  4:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 12:03 [PATCH] drm/lima: call drm_mm_init() with a valid allocation range Henrik Grimler
2026-06-02  7:16 ` Qiang Yu
2026-06-04  4:10 ` Claude Code Review Bot [this message]
2026-06-04  4:10 ` 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-patch1-20260601-lima-alloc-fix-v1-1-16d3f3b7b780@axis.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