Jani Nikula (4): drm/amdgpu: fix -Wformat-truncation warning in amdgpu_gfx_kiq_init_ring() drm/nouveau: fix -Wformat-truncation warning in nouveau_backlight_init() drm/imx: fix -Wformat-truncation warning in imx_ldb_probe() drm: enable -Wformat-truncation across the subsystem drivers/gpu/drm/Makefile | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 6 ++++-- drivers/gpu/drm/imx/ipuv3/imx-ldb.c | 6 +++++- drivers/gpu/drm/nouveau/nouveau_backlight.c | 9 +++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) -- 2.39.2
Jani Nikula
2024-May-23 15:51 UTC
[PATCH 1/4] drm/amdgpu: fix -Wformat-truncation warning in amdgpu_gfx_kiq_init_ring()
Enabling -Wformat-truncation yields the following warning: ../drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c: In function ?amdgpu_gfx_kiq_init_ring?: ../drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c:332:61: error: ?%d? directive output may be truncated writing between 1 and 10 bytes into a region of size between 0 and 8 [-Werror=format-truncation=] 332 | snprintf(ring->name, sizeof(ring->name), "kiq_%d.%d.%d.%d", | ^~ ../drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c:332:50: note: directive argument in the range [0, 2147483647] 332 | snprintf(ring->name, sizeof(ring->name), "kiq_%d.%d.%d.%d", | ^~~~~~~~~~~~~~~~~ ../drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c:332:9: note: ?snprintf? output between 12 and 41 bytes into a destination of size 16 332 | snprintf(ring->name, sizeof(ring->name), "kiq_%d.%d.%d.%d", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 333 | xcc_id, ring->me, ring->pipe, ring->queue); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Silence the warning by checking the snprintf() return value. Signed-off-by: Jani Nikula <jani.nikula at intel.com> --- Cc: Alex Deucher <alexander.deucher at amd.com> Cc: "Christian K?nig" <christian.koenig at amd.com> Cc: Pan Xinhui <Xinhui.Pan at amd.com> Cc: amd-gfx at lists.freedesktop.org Cc: dri-devel at lists.freedesktop.org --- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c index 1d955652f3ba..92744d0d2c10 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c @@ -329,8 +329,10 @@ int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev, int xcc_id) ring->eop_gpu_addr = kiq->eop_gpu_addr; ring->no_scheduler = true; - snprintf(ring->name, sizeof(ring->name), "kiq_%d.%d.%d.%d", - xcc_id, ring->me, ring->pipe, ring->queue); + r = snprintf(ring->name, sizeof(ring->name), "kiq_%d.%d.%d.%d", + xcc_id, ring->me, ring->pipe, ring->queue); + if (r >= sizeof(ring->name)) + dev_warn(adev->dev, "kiq ring name truncated\n"); r = amdgpu_ring_init(adev, ring, 1024, irq, AMDGPU_CP_KIQ_IRQ_DRIVER0, AMDGPU_RING_PRIO_DEFAULT, NULL); if (r) -- 2.39.2
Jani Nikula
2024-May-23 15:51 UTC
[PATCH 2/4] drm/nouveau: fix -Wformat-truncation warning in nouveau_backlight_init()
Enabling -Wformat-truncation yields the following warning: ../drivers/gpu/drm/nouveau/nouveau_backlight.c: In function ?nouveau_backlight_init?: ../drivers/gpu/drm/nouveau/nouveau_backlight.c:56:69: error: ?%d? directive output may be truncated writing between 1 and 10 bytes into a region of size 3 [-Werror=format-truncation=] 56 | snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); | ^~ In function ?nouveau_get_backlight_name?, inlined from ?nouveau_backlight_init? at ../drivers/gpu/drm/nouveau/nouveau_backlight.c:351:7: ../drivers/gpu/drm/nouveau/nouveau_backlight.c:56:56: note: directive argument in the range [1, 2147483647] 56 | snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); | ^~~~~~~~~~~~~~~~ ../drivers/gpu/drm/nouveau/nouveau_backlight.c:56:17: note: ?snprintf? output between 14 and 23 bytes into a destination of size 15 56 | snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Silence the warning by checking the snprintf() return value. Signed-off-by: Jani Nikula <jani.nikula at intel.com> --- Cc: Karol Herbst <kherbst at redhat.com> Cc: Lyude Paul <lyude at redhat.com> Cc: Danilo Krummrich <dakr at redhat.com> Cc: dri-devel at lists.freedesktop.org Cc: nouveau at lists.freedesktop.org --- drivers/gpu/drm/nouveau/nouveau_backlight.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c index d47442125fa1..1d77a5f280c5 100644 --- a/drivers/gpu/drm/nouveau/nouveau_backlight.c +++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c @@ -49,13 +49,18 @@ nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE], struct nouveau_backlight *bl) { const int nb = ida_alloc_max(&bl_ida, 99, GFP_KERNEL); + int ret; if (nb < 0) return false; if (nb > 0) - snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); + ret = snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); else - snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight"); + ret = snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight"); + + if (ret >= BL_NAME_SIZE) + return false; + bl->id = nb; return true; } -- 2.39.2
Jani Nikula
2024-May-23 15:51 UTC
[PATCH 3/4] drm/imx: fix -Wformat-truncation warning in imx_ldb_probe()
Enabling -Wformat-truncation yields the following warning: ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c: In function ?imx_ldb_probe?: ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c:658:57: error: ?_sel? directive output may be truncated writing 4 bytes into a region of size between 3 and 13 [-Werror=format-truncation=] 658 | snprintf(clkname, sizeof(clkname), "di%d_sel", i); | ^~~~ ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c:658:17: note: ?snprintf? output between 8 and 18 bytes into a destination of size 16 658 | snprintf(clkname, sizeof(clkname), "di%d_sel", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Silence the warning by checking the snprintf() return value. Signed-off-by: Jani Nikula <jani.nikula at intel.com> --- Cc: Philipp Zabel <p.zabel at pengutronix.de> Cc: Shawn Guo <shawnguo at kernel.org> Cc: Sascha Hauer <s.hauer at pengutronix.de> Cc: Pengutronix Kernel Team <kernel at pengutronix.de> Cc: Fabio Estevam <festevam at gmail.com> Cc: dri-devel at lists.freedesktop.org Cc: imx at lists.linux.dev --- drivers/gpu/drm/imx/ipuv3/imx-ldb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c index 71d70194fcbd..46f779fe60ee 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c @@ -654,8 +654,12 @@ static int imx_ldb_probe(struct platform_device *pdev) */ for (i = 0; i < 4; i++) { char clkname[16]; + int len; + + len = snprintf(clkname, sizeof(clkname), "di%d_sel", i); + if (len >= sizeof(clkname)) + dev_err(dev, "clkname truncated\n"); - snprintf(clkname, sizeof(clkname), "di%d_sel", i); imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname); if (IS_ERR(imx_ldb->clk_sel[i])) { ret = PTR_ERR(imx_ldb->clk_sel[i]); -- 2.39.2
Jani Nikula
2024-May-23 15:51 UTC
[PATCH 4/4] drm: enable -Wformat-truncation across the subsystem
With the -Wformat-truncation warnings fixed, finish the job started in commit a61ddb4393ad ("drm: enable (most) W=1 warnings by default across the subsystem"), and enable that warning too. Signed-off-by: Jani Nikula <jani.nikula at intel.com> --- Gut feeling says there are more issues, and my configs just don't catch them all, but let's see what the build bots have to say. ;) --- drivers/gpu/drm/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 68cc9258ffc4..644613dbedda 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -16,8 +16,7 @@ subdir-ccflags-y += $(call cc-option, -Wunused-but-set-variable) subdir-ccflags-y += $(call cc-option, -Wunused-const-variable) subdir-ccflags-y += $(call cc-option, -Wpacked-not-aligned) subdir-ccflags-y += $(call cc-option, -Wformat-overflow) -# FIXME: fix -Wformat-truncation warnings and uncomment -#subdir-ccflags-y += $(call cc-option, -Wformat-truncation) +subdir-ccflags-y += $(call cc-option, -Wformat-truncation) subdir-ccflags-y += $(call cc-option, -Wstringop-truncation) # The following turn off the warnings enabled by -Wextra ifeq ($(findstring 2, $(KBUILD_EXTRA_WARN)),) -- 2.39.2
Seemingly Similar Threads
- [PATCH 3/4] drm/imx: fix -Wformat-truncation warning in imx_ldb_probe()
- [PATCH 3/4] drm/imx: fix -Wformat-truncation warning in imx_ldb_probe()
- [PATCH 1/4] drm/amdgpu: fix -Wformat-truncation warning in amdgpu_gfx_kiq_init_ring()
- [PATCH 1/2] nouveau/bl: Assign different names to interfaces
- [PATCH 0/2] drm/nouveau: Fix panic on nouveau unload.