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/nouveau: Wire up dmem cgroups
Date: Sun, 12 Apr 2026 10:21:18 +1000	[thread overview]
Message-ID: <review-patch1-20260410081322.5577-1-natalie.vock@gmx.de> (raw)
In-Reply-To: <20260410081322.5577-1-natalie.vock@gmx.de>

Patch Review

**Concept: Correct.** The registration is placed in the right location within `nouveau_ttm_init_vram()`, on the Tesla+ path where `man` is dynamically allocated. The header for `drmm_cgroup_register_region` is available transitively via `nouveau_drv.h` -> `drm/drm_drv.h`. The region name `"vram"` and size `drm->gem.vram_available` are appropriate and consistent with what amdgpu/xe do.

**Bug: Memory leak of `man` on cgroup registration failure.**

Looking at the patched code (lines 183–194):

```c
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
    struct ttm_resource_manager *man = kzalloc_obj(*man);

    if (!man)
        return -ENOMEM;

    man->func = &nouveau_vram_manager;

    man->cg = drmm_cgroup_register_region(drm->dev, "vram",
                          drm->gem.vram_available);
    if (IS_ERR(man->cg))
        return PTR_ERR(man->cg);
```

If `drmm_cgroup_register_region()` fails, the function returns immediately via `return PTR_ERR(man->cg)` without freeing `man`, which was allocated with `kzalloc_obj()` at line 184. This is a memory leak.

By contrast, in the amdgpu driver (`amdgpu_vram_mgr.c:917-923`), `man` is embedded within `struct amdgpu_vram_mgr` (not separately heap-allocated), so there's no analogous leak. The nouveau code allocates `man` on the heap and must free it on all error paths.

**Fix:** Add `kfree(man)` before the error return:

```c
    if (IS_ERR(man->cg)) {
        kfree(man);
        return PTR_ERR(man->cg);
    }
```

Note: there is a subtlety — `man->cg` is read after `kfree(man)` in `PTR_ERR(man->cg)`. To be safe, this should use a local variable:

```c
    if (IS_ERR(man->cg)) {
        int ret = PTR_ERR(man->cg);
        kfree(man);
        return ret;
    }
```

**Pre-Tesla path:** The `else` branch (line 201–203) uses `ttm_range_man_init()` which handles its own allocation internally. There is no cgroup registration for this path, which seems intentional and reasonable (pre-Tesla hardware is quite old).

**No-op when cgroups disabled:** `drmm_cgroup_register_region()` should return a non-error value when `CONFIG_CGROUP_DMEM` is not enabled (a stub), so this won't break builds without cgroup support. This is fine.

**Summary:** The patch is the right approach but needs the `kfree(man)` leak fix on the error path. With that addressed, this is a clean, minimal addition. Worth also considering whether a `Cc: stable` tag is warranted (probably not — this is new functionality, not a fix).

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-04-12  0:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10  8:13 [PATCH] drm/nouveau: Wire up dmem cgroups Natalie Vock
2026-04-12  0:21 ` Claude Code Review Bot [this message]
2026-04-12  0:21 ` 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-20260410081322.5577-1-natalie.vock@gmx.de \
    --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