From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: drm/nouveau: Wire up dmem cgroups Date: Sun, 12 Apr 2026 10:21:18 +1000 Message-ID: In-Reply-To: <20260410081322.5577-1-natalie.vock@gmx.de> References: <20260410081322.5577-1-natalie.vock@gmx.de> <20260410081322.5577-1-natalie.vock@gmx.de> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **Concept: Correct.** The registration is placed in the right location with= in `nouveau_ttm_init_vram()`, on the Tesla+ path where `man` is dynamically= allocated. The header for `drmm_cgroup_register_region` is available trans= itively via `nouveau_drv.h` -> `drm/drm_drv.h`. The region name `"vram"` an= d size `drm->gem.vram_available` are appropriate and consistent with what a= mdgpu/xe do. **Bug: Memory leak of `man` on cgroup registration failure.** Looking at the patched code (lines 183=E2=80=93194): ```c if (drm->client.device.info.family >=3D NV_DEVICE_INFO_V0_TESLA) { struct ttm_resource_manager *man =3D kzalloc_obj(*man); if (!man) return -ENOMEM; man->func =3D &nouveau_vram_manager; man->cg =3D 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 wi= th `kzalloc_obj()` at line 184. This is a memory leak. By contrast, in the amdgpu driver (`amdgpu_vram_mgr.c:917-923`), `man` is e= mbedded within `struct amdgpu_vram_mgr` (not separately heap-allocated), so= there's no analogous leak. The nouveau code allocates `man` on the heap an= d 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 =E2=80=94 `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 =3D PTR_ERR(man->cg); kfree(man); return ret; } ``` **Pre-Tesla path:** The `else` branch (line 201=E2=80=93203) uses `ttm_rang= e_man_init()` which handles its own allocation internally. There is no cgro= up 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 ret= urn 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)` lea= k fix on the error path. With that addressed, this is a clean, minimal addi= tion. Worth also considering whether a `Cc: stable` tag is warranted (proba= bly not =E2=80=94 this is new functionality, not a fix). --- Generated by Claude Code Patch Reviewer