public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init()
@ 2026-05-22  9:19 Dongyang Jin
  2026-05-25  9:07 ` Claude review: " Claude Code Review Bot
  2026-05-25  9:07 ` Claude Code Review Bot
  0 siblings, 2 replies; 3+ messages in thread
From: Dongyang Jin @ 2026-05-22  9:19 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, airlied, simona,
	sathishkumar.sundararaju, yinjie.yao, michal.simek
  Cc: amd-gfx, dri-devel, linux-kernel, Dongyang Jin, kernel test robot

A false-positive compile warnings:

drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c: In function 'jpeg_v2_5_sw_init':
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c:152:68: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Wformat-truncation=]
  152 |                 snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%d", i);
      |                                                                    ^~
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c:152:58: note: directive argument in the range [-2147483643, 255]
  152 |                 snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%d", i);
      |                                                          ^~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c:152:17: note: 'snprintf' output between 11 and 21 bytes into a destination of size 16
  152 |                 snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%d", i);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Suppress it by replacing the type of variable i with uint8_t.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202605212104.SAIMqegX-lkp@intel.com/
Signed-off-by: Dongyang Jin <jindongyang@kylinos.cn>
---
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index 5208312e7017..a88a1e1d6423 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
@@ -104,7 +104,8 @@ static int jpeg_v2_5_early_init(struct amdgpu_ip_block *ip_block)
 static int jpeg_v2_5_sw_init(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_ring *ring;
-	int i, r;
+	uint8_t i;
+	int r;
 	struct amdgpu_device *adev = ip_block->adev;
 
 	for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
@@ -149,7 +150,7 @@ static int jpeg_v2_5_sw_init(struct amdgpu_ip_block *ip_block)
 		else
 			ring->vm_hub = AMDGPU_MMHUB0(0);
 		ring->doorbell_index = (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + 1 + 8 * i;
-		snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%d", i);
+		snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%u", i);
 		r = amdgpu_ring_init(adev, ring, 512, &adev->jpeg.inst[i].irq,
 				     0, AMDGPU_RING_PRIO_DEFAULT, NULL);
 		if (r)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Claude review: drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init()
  2026-05-22  9:19 [PATCH] drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init() Dongyang Jin
@ 2026-05-25  9:07 ` Claude Code Review Bot
  2026-05-25  9:07 ` Claude Code Review Bot
  1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-05-25  9:07 UTC (permalink / raw)
  To: dri-devel-reviews

Overall Series Review

Subject: drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init()
Author: Dongyang Jin <jindongyang@kylinos.cn>
Patches: 1
Reviewed: 2026-05-25T19:07:47.282791

---

This is a single-patch series that fixes a `-Wformat-truncation` compiler warning in `jpeg_v2_5_sw_init()`. The warning arises because GCC can't prove that the loop variable `i` (declared as `int`) will always fit within the remaining buffer space of `ring->name[16]` when formatted as `"jpeg_dec_%d"` (prefix is 9 chars + NUL = at most 6 chars for the number, but a full `int` could be 11 digits plus a sign).

The fix narrows the loop variable `i` from `int` to `uint8_t` and changes the format specifier from `%d` to `%u`. This is correct and consistent: `num_jpeg_inst` is already declared as `uint8_t` in `amdgpu_jpeg.h:132`, so the loop counter can never exceed 255, which is at most 3 digits — well within the buffer.

**Verdict: Looks good.** The fix is minimal, correct, and addresses the root cause rather than papering over it with a cast or pragma. One minor style nit below.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Claude review: drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init()
  2026-05-22  9:19 [PATCH] drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init() Dongyang Jin
  2026-05-25  9:07 ` Claude review: " Claude Code Review Bot
@ 2026-05-25  9:07 ` Claude Code Review Bot
  1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-05-25  9:07 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Status: Acceptable (minor nit)**

**The type change is well-motivated and correct.** Since `adev->jpeg.num_jpeg_inst` is `uint8_t` (from `amdgpu_jpeg.h:132`), narrowing the loop variable to match is a natural fix. A `uint8_t` value formatted with `%u` produces at most 3 characters ("255"), so `"jpeg_dec_255\0"` = 13 bytes, which comfortably fits in `ring->name[16]`.

**The format specifier change from `%d` to `%u` is correct:**
```c
snprintf(ring->name, sizeof(ring->name), "jpeg_dec_%u", i);
```
Since `i` is now unsigned, `%u` is the matching specifier. Good.

**Minor style nit:** The declaration ordering changed slightly:
```c
	struct amdgpu_ring *ring;
	uint8_t i;
	int r;
	struct amdgpu_device *adev = ip_block->adev;
```
This is fine and follows the existing pattern in the file of grouping declarations by type. No issue here.

**One consideration:** The `harvest_config` mask expression `(1 << i)` at line 112 and 143 is safe with `uint8_t i` — `i` gets integer-promoted and the shift is well-defined for values 0–255 (though in practice `num_jpeg_inst` is small, typically 1–2).

**No functional concerns.** The patch is minimal and solves exactly the reported problem.

Reviewed-by recommendation: **Acceptable as-is.**

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-25  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22  9:19 [PATCH] drm/amdgpu/jpeg: Fix format-truncation warning in jpeg_v2_5_sw_init() Dongyang Jin
2026-05-25  9:07 ` Claude review: " Claude Code Review Bot
2026-05-25  9:07 ` Claude Code Review Bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox