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] cgroup/dmem: return -ENOMEM on failed pool preallocation
Date: Sat, 16 May 2026 15:56:05 +1000	[thread overview]
Message-ID: <review-patch1-c6b89ff53b603350fe53b0d47f3399ed@kernel.org> (raw)
In-Reply-To: <c6b89ff53b603350fe53b0d47f3399ed@kernel.org>

Patch Review

**Correctness: Correct.**

Looking at the function flow (lines 585–606 in the current tree):

```c
while (!pool) {
    spin_lock(&dmemcg_lock);
    if (!region->unregistered)
        pool = get_cg_pool_locked(cg, region, &allocpool);
    else
        pool = ERR_PTR(-ENODEV);
    ...
    spin_unlock(&dmemcg_lock);

    if (pool == ERR_PTR(-ENOMEM)) {
        pool = NULL;
        if (WARN_ON(allocpool))
            continue;

        allocpool = kzalloc_obj(*allocpool);
        if (allocpool) {
            pool = NULL;
            continue;
        }
        // <--- BUG: pool is NULL here, loop retries forever
    }
}
```

When `kzalloc_obj()` returns NULL (allocation failure), execution falls through the `if (allocpool)` block without setting `pool`. Since `pool` was set to NULL at line 596 (`pool = NULL`), the `while (!pool)` condition is still true, and the loop retries. But `allocpool` is also still NULL, so the next iteration will call `get_cg_pool_locked()` without a preallocated pool, which will again return `ERR_PTR(-ENOMEM)`, and the cycle repeats — an infinite loop under memory pressure, exactly when you'd least want it.

The fix:

```c
        allocpool = kzalloc_obj(*allocpool);
        if (allocpool) {
            pool = NULL;
            continue;
        }
+       pool = ERR_PTR(-ENOMEM);
    }
```

This causes the `while (!pool)` loop to terminate (since `ERR_PTR(-ENOMEM)` is non-NULL), and `pool` is returned to the caller. Since callers already check for `IS_ERR()` returns (the `-ENODEV` path at line 590 already sets an ERR_PTR), this is consistent with the existing error contract.

**Minor observations:**

1. The `Fixes:` tag references the correct commit that introduced the dmem cgroup code.
2. The `kfree(allocpool)` at line 608 is safe since `allocpool` is NULL in this error path.
3. One could argue that `GFP_KERNEL` allocation failure should perhaps use `__GFP_NOFAIL` or retry with `GFP_NOIO` depending on context, but simply propagating the error is the safest and most standard approach, and matches how `get_cg_pool_locked` already signals `-ENOMEM`.

**No issues found. Clean, minimal, correct fix.**

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-05-16  5:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11  1:31 [PATCH] cgroup/dmem: return -ENOMEM on failed pool preallocation Guopeng Zhang
2026-05-11  1:46 ` Tejun Heo
2026-05-16  5:56   ` Claude review: " Claude Code Review Bot
2026-05-16  5:56   ` Claude Code Review Bot [this message]
2026-05-11 13:03 ` Michal Koutný
     [not found] ` <1778555389652035.138.seg@mailgw.kylinos.cn>
2026-05-12  7:04   ` Guopeng Zhang

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-c6b89ff53b603350fe53b0d47f3399ed@kernel.org \
    --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