@@ -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;
}
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@intel.com> --- Cc: Karol Herbst <kherbst@redhat.com> Cc: Lyude Paul <lyude@redhat.com> Cc: Danilo Krummrich <dakr@redhat.com> Cc: dri-devel@lists.freedesktop.org Cc: nouveau@lists.freedesktop.org --- drivers/gpu/drm/nouveau/nouveau_backlight.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)