From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm_buddy: fix power-of-2 rounding errs
Date: Tue, 10 Mar 2026 12:46:56 +1000 [thread overview]
Message-ID: <review-patch1-20260308223538.96729-2-jim.cromie@gmail.com> (raw)
In-Reply-To: <20260308223538.96729-2-jim.cromie@gmail.com>
Patch Review
**Problem analysis**: Correct. `roundup_pow_of_two()` and `rounddown_pow_of_two()` both use `unsigned long` internally (confirmed at `linux/include/linux/log2.h:55-67` — `1UL << fls_long(n - 1)` and `1UL << (fls_long(n) - 1)`). On 32-bit arches, `unsigned long` is 32 bits, so any `u64` value > 4GB is silently truncated.
**Rounddown fix** (line 306):
```c
- modify_size = rounddown_pow_of_two(size);
+ modify_size = 1ULL << ilog2(size);
```
This is correct. `ilog2()` handles `u64` properly, and `1ULL << ilog2(size)` is equivalent to `rounddown_pow_of_two(size)` for non-zero, non-power-of-two inputs. For inputs that are already powers of two, both return the same value.
**Roundup fix** (line 315):
```c
- size = roundup_pow_of_two(size);
+ size = 1ULL << (ilog2(size - 1) + 1);
```
**Bug**: This has an edge case problem. When `size` is already a power of two (e.g., `size = 4`), `ilog2(size - 1)` = `ilog2(3)` = 1, so the result is `1ULL << 2` = 4, which is correct. When `size = 1`, `ilog2(0)` is undefined behavior — `ilog2(0)` returns `-1` on most implementations, so `1ULL << 0` = 1, which happens to work but relies on undefined behavior for `ilog2(0)`.
However, given the calling context (this is inside `drm_buddy_alloc_blocks` with contiguous allocation), `size` should never be 0 or 1 in practice (it's a memory allocation size that's been validated), so this is likely fine in practice.
**Suggestion**: The commit message mentions "I'll use it to implement safe rounding" which is a bit informal for a commit message — first person and future tense. Consider also adding a `Fixes:` tag — the original `rounddown_pow_of_two()` / `roundup_pow_of_two()` calls have been present since the initial drm_buddy code was merged, and this is a legitimate bug on 32-bit architectures. Also, the kernel now has `roundup_pow_of_two_u64()` / `rounddown_pow_of_two_u64()` in some trees — it might be worth checking if those helpers exist or are more appropriate than hand-rolling the `ilog2` pattern.
**Missing Cc: stable**: For a genuine 32-bit architecture bug, a `Cc: stable@vger.kernel.org` tag would be appropriate.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-03-10 2:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 22:35 [PATCH 0/2] 2 bugfixes found in DRM-CI Jim Cromie
2026-03-08 22:35 ` [PATCH 1/2] drm_buddy: fix power-of-2 rounding errs Jim Cromie
2026-03-10 2:46 ` Claude Code Review Bot [this message]
2026-03-08 22:35 ` [PATCH 2/2] drivers/gpu/drm/drm_print: fix drm_printer dynamic debug bypass Jim Cromie
2026-03-10 2:46 ` Claude review: " Claude Code Review Bot
2026-03-10 2:46 ` Claude review: 2 bugfixes found in DRM-CI 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-20260308223538.96729-2-jim.cromie@gmail.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