Re: [PATCH] Input: cobra - use scnprintf() for the device physical path
From: Dmitry Torokhov
Date: Thu Nov 26 2026 - 00:48:53 EST
On Thu, Nov 26, 2026 at 11:52:06AM +0800, Aibing Chen wrote:
> cobra_connect() composes the physical path of each port as "%s/input%d"
> from gameport->phys into a 32 byte array. gameport->phys can hold up to
> 31 characters, so the composed string reaches 39 bytes and does not fit.
> The path is informational only and truncating it is acceptable, but the
> call site does not say so.
>
> Building with W=1, where -Wformat-truncation is enabled, the file does not
> build at all today; COMPILE_TEST configurations additionally turn the
> warning into an error through CONFIG_WERROR:
>
> drivers/input/joystick/cobra.c:184:29: error: '/input' directive output
> may be truncated writing 6 bytes into a region of size between 1 and
> 32 [-Werror=format-truncation=]
> note: 'snprintf' output between 8 and 39 bytes into a destination of
> size 32
>
> Use scnprintf(), the helper that expresses a bounded, truncation tolerant
> write, so that the file builds warning free and the intent is visible at
> the call site.
>
> No functional change.
>
> Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
Applied, thank you.
--
Dmitry