[PATCH] drm/i915/display: Avoid nonliteral printf format string

Arnd Bergmann posted 1 patch 2 weeks, 1 day ago
drivers/gpu/drm/i915/display/intel_display.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH] drm/i915/display: Avoid nonliteral printf format string
Posted by Arnd Bergmann 2 weeks, 1 day ago
From: Arnd Bergmann <arnd@arndb.de>

pipe_config_mismatch() takes a printf-style format string and arguments,
not a constant string, so this trigers -Wformat warnings when they are
not disabled:

drivers/gpu/drm/i915/display/intel_display.c: In function 'pipe_config_cx0pll_mismatch':
drivers/gpu/drm/i915/display/intel_display.c:4997:9: error: format not a string literal and no format arguments [-Werror=format-security]
 4997 |         pipe_config_mismatch(p, fastset, crtc, name, chipname);
      |         ^~~~~~~~~~~~~~~~~~~~

drivers/gpu/drm/i915/display/intel_display.c: In function 'pipe_config_lt_phy_pll_mismatch':
drivers/gpu/drm/i915/display/intel_display.c:5027:9: error: format not a string literal and no format arguments [-Werror=format-security]
 5027 |         pipe_config_mismatch(p, fastset, crtc, name, chipname);
      |         ^~~~~~~~~~~~~~~~~~~~

Use either the string literal or the trivial "%s" format so the compiler can
prove this to be used correctly.

Fixes: 45fe957ae769 ("drm/i915/display: Add compare config for MTL+ platforms")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/i915/display/intel_display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index 7b4fd18c60e2..83025d5a4aa9 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -4987,7 +4987,7 @@ pipe_config_cx0pll_mismatch(struct drm_printer *p, bool fastset,
 	struct intel_display *display = to_intel_display(crtc);
 	char *chipname = a->use_c10 ? "C10" : "C20";
 
-	pipe_config_mismatch(p, fastset, crtc, name, chipname);
+	pipe_config_mismatch(p, fastset, crtc, name, "%s", chipname);
 
 	drm_printf(p, "expected:\n");
 	intel_cx0pll_dump_hw_state(display, a);
@@ -5022,9 +5022,8 @@ pipe_config_lt_phy_pll_mismatch(struct drm_printer *p, bool fastset,
 				const struct intel_lt_phy_pll_state *b)
 {
 	struct intel_display *display = to_intel_display(crtc);
-	char *chipname = "LTPHY";
 
-	pipe_config_mismatch(p, fastset, crtc, name, chipname);
+	pipe_config_mismatch(p, fastset, crtc, name, "LTPHY");
 
 	drm_printf(p, "expected:\n");
 	intel_lt_phy_dump_hw_state(display, a);
-- 
2.39.5
Re: [PATCH] drm/i915/display: Avoid nonliteral printf format string
Posted by Jani Nikula 2 weeks, 1 day ago
On Thu, 04 Dec 2025, Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> pipe_config_mismatch() takes a printf-style format string and arguments,
> not a constant string, so this trigers -Wformat warnings when they are
> not disabled:
>
> drivers/gpu/drm/i915/display/intel_display.c: In function 'pipe_config_cx0pll_mismatch':
> drivers/gpu/drm/i915/display/intel_display.c:4997:9: error: format not a string literal and no format arguments [-Werror=format-security]
>  4997 |         pipe_config_mismatch(p, fastset, crtc, name, chipname);
>       |         ^~~~~~~~~~~~~~~~~~~~
>
> drivers/gpu/drm/i915/display/intel_display.c: In function 'pipe_config_lt_phy_pll_mismatch':
> drivers/gpu/drm/i915/display/intel_display.c:5027:9: error: format not a string literal and no format arguments [-Werror=format-security]
>  5027 |         pipe_config_mismatch(p, fastset, crtc, name, chipname);
>       |         ^~~~~~~~~~~~~~~~~~~~
>
> Use either the string literal or the trivial "%s" format so the compiler can
> prove this to be used correctly.
>
> Fixes: 45fe957ae769 ("drm/i915/display: Add compare config for MTL+ platforms")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Unfortunately, this no longer applies to
drm-intel-next. pipe_config_cx0pll_mismatch() no longer exists. The 2nd
hunk is still valid, though, want to send a rebased version?

BR,
Jani.


> ---
>  drivers/gpu/drm/i915/display/intel_display.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> index 7b4fd18c60e2..83025d5a4aa9 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -4987,7 +4987,7 @@ pipe_config_cx0pll_mismatch(struct drm_printer *p, bool fastset,
>  	struct intel_display *display = to_intel_display(crtc);
>  	char *chipname = a->use_c10 ? "C10" : "C20";
>  
> -	pipe_config_mismatch(p, fastset, crtc, name, chipname);
> +	pipe_config_mismatch(p, fastset, crtc, name, "%s", chipname);
>  
>  	drm_printf(p, "expected:\n");
>  	intel_cx0pll_dump_hw_state(display, a);
> @@ -5022,9 +5022,8 @@ pipe_config_lt_phy_pll_mismatch(struct drm_printer *p, bool fastset,
>  				const struct intel_lt_phy_pll_state *b)
>  {
>  	struct intel_display *display = to_intel_display(crtc);
> -	char *chipname = "LTPHY";
>  
> -	pipe_config_mismatch(p, fastset, crtc, name, chipname);
> +	pipe_config_mismatch(p, fastset, crtc, name, "LTPHY");
>  
>  	drm_printf(p, "expected:\n");
>  	intel_lt_phy_dump_hw_state(display, a);

-- 
Jani Nikula, Intel