From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/amd/ras: Fix type size of remainder argument
Date: Fri, 27 Feb 2026 14:18:28 +1000 [thread overview]
Message-ID: <review-patch1-20260225014317.work.103-kees@kernel.org> (raw)
In-Reply-To: <20260225014317.work.103-kees@kernel.org>
Patch Review
**Problem analysis:** The original code at line 70-72 of `ras_core.c` declares:
```c
int days, remaining_seconds;
...
days = div64_u64_rem(timestamp, seconds_per_day, (uint64_t *)&remaining_seconds);
```
`div64_u64_rem()` has the signature (from `include/linux/math64.h:54`):
```c
static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
```
Writing a `u64` (8 bytes) through a pointer to a 4-byte `int` is an out-of-bounds stack write. On little-endian x86 this happens to work by luck (the low 4 bytes land correctly, and the high 4 bytes overflow into adjacent stack space), but it's undefined behavior and would produce wrong results on big-endian architectures.
**Fix review:** The patch changes `remaining_seconds` from `int` to `uint64_t` and removes the cast:
```c
+ uint64_t remaining_seconds;
...
+ days = div64_u64_rem(timestamp, seconds_per_day, &remaining_seconds);
```
This is the correct fix. The value stored in `remaining_seconds` (seconds within a day, range 0–86399) fits comfortably in any integer type, so the widening has no functional impact on the subsequent arithmetic at lines 97-100 where `remaining_seconds` is used for division/modulo to compute hours, minutes, and seconds.
**Minor observations (not blocking):**
1. The return type of `div64_u64_rem()` is `u64`, but `days` remains `int`. For timestamp values representable by a `u64`, the number of days could theoretically exceed `INT_MAX` (~5.8 million years), but practically this is fine since the function processes realistic Unix timestamps. Not something this patch needs to address.
2. The `seconds_per_day`, `seconds_per_hour`, and `seconds_per_minute` variables are `int`, and they are passed as the `u64 divisor` argument to `div64_u64_rem()` — this is an implicit widening conversion which is safe and correct. No issue here.
**Reviewed-by: Looks correct.** The fix is minimal, targeted, and solves both the `-Warray-bounds` warning and the underlying type-safety/endianness bug.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-02-27 4:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 1:43 [PATCH] drm/amd/ras: Fix type size of remainder argument Kees Cook
2026-02-25 17:28 ` Kees Cook
2026-02-27 4:18 ` Claude Code Review Bot [this message]
2026-02-27 4:18 ` Claude review: " Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-02-25 17:47 [PATCH v2] " Kees Cook
2026-02-27 3:07 ` Claude review: " Claude Code Review Bot
2026-02-27 3:07 ` 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-20260225014317.work.103-kees@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