* [PATCH] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init
@ 2026-11-23 23:11 Arnaud Bonnet
2026-11-24 8:59 ` sashiko-bot
2026-11-25 16:11 ` [PATCH v2] " Arnaud Bonnet
0 siblings, 2 replies; 3+ messages in thread
From: Arnaud Bonnet @ 2026-11-23 23:11 UTC (permalink / raw)
To: alexander.deucher, christian.koenig; +Cc: amd-gfx, dri-devel, Arnaud Bonnet
When doing sw initialization of JPEG for v2.5, the formatting function
snprintf is used with format string "jpeg_dec_%d", where d refers to the
instance index of type int. This leads to the following compiler warning
with several GCC versions as the compiler is unable to derive a safe
upper bound for the formatted index size:
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 [-2147483641, 254]
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Since no VCN block seems to have more than 64 JPEG instances, it is safe
to change the format specifier to %hd which fixes the warning and allows
to build the driver with CONFIG_DRM_AMDGPU_WERROR enabled.
Signed-off-by: Arnaud Bonnet <abo@medichon.fr>
---
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index 966a8a7f28ee..e2ba58cbff5c 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
@@ -149,7 +149,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_%hd", i);
r = amdgpu_ring_init(adev, ring, 512, &adev->jpeg.inst[i].irq,
0, AMDGPU_RING_PRIO_DEFAULT, NULL);
if (r)
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init
2026-11-23 23:11 [PATCH] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init Arnaud Bonnet
@ 2026-11-24 8:59 ` sashiko-bot
2026-11-25 16:11 ` [PATCH v2] " Arnaud Bonnet
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-24 8:59 UTC (permalink / raw)
To: Arnaud Bonnet; +Cc: amd-gfx, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: snprintf() %hd type mismatch with int i in
jpeg_v2_5_sw_init()
--
commit bb4e12d069d5e73451e34365a02677da5fad2d5f
Author: Arnaud Bonnet <abo@medichon.fr>
drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init
This commit changes the snprintf() format specifier for the JPEG ring name
in jpeg_v2_5_sw_init() from %d to %hd to silence a GCC -Wformat-truncation
warning.
> diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
> index 966a8a7f28eed..e2ba58cbff5cb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
> +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
> @@ -149,7 +149,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_%hd", i);
[Severity: Medium]
Does passing int i to %hd introduce a -Wformat warning when building with
Clang?
In jpeg_v2_5_sw_init(), i is declared as int, so Clang warns that the
format specifies type short while the argument has type int, breaking
builds with CONFIG_DRM_AMDGPU_WERROR=y or CONFIG_WERROR=y. Declaring i as
unsigned int and using %u avoids both the GCC truncation warning and the
Clang type mismatch.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123231150.26328-1-abo@medichon.fr?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init
2026-11-23 23:11 [PATCH] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init Arnaud Bonnet
2026-11-24 8:59 ` sashiko-bot
@ 2026-11-25 16:11 ` Arnaud Bonnet
1 sibling, 0 replies; 3+ messages in thread
From: Arnaud Bonnet @ 2026-11-25 16:11 UTC (permalink / raw)
To: abo, alexander.deucher, christian.koenig; +Cc: amd-gfx
When doing sw initialization of JPEG for v2.5, the formatting function
snprintf is used with format string "jpeg_dec_%d", where d formats the
instance index of type int. This leads to the following compiler warning
with several GCC versions as the compiler is unable to derive a safe
upper bound for the formatted index size under W=1:
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 [-2147483641, 254]
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change to the %hhu format instead, which is safe as the instance count
always fits an unsigned char and allows to build the driver with
CONFIG_DRM_AMDGPU_WERROR enabled.
Fixes: ad0150fa2fad ("drm/amdgpu/jpeg: Fix sprintf buffer overflow warning in jpeg_v2_5")
Signed-off-by: Arnaud Bonnet <abo@medichon.fr>
---
v2:
* change format from %hd to %hhu for consistency with fix in commit
0ea554455542 ("drm/amdgpu: Fix snprintf usage in
amdgpu_gfx_kiq_init_ring")
* add Fixes: tag
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index 966a8a7f28ee..59c9a9283aad 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
@@ -149,7 +149,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_%hhu", (unsigned char)i);
r = amdgpu_ring_init(adev, ring, 512, &adev->jpeg.inst[i].irq,
0, AMDGPU_RING_PRIO_DEFAULT, NULL);
if (r)
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 8:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 23:11 [PATCH] drm/amdgpu: fix string format compiler warning in jpeg_v2_5_sw_init Arnaud Bonnet
2026-11-24 8:59 ` sashiko-bot
2026-11-25 16:11 ` [PATCH v2] " Arnaud Bonnet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.