[PATCH] Input: cobra - use scnprintf() for the device physical path

From: Aibing Chen

Date: Wed Nov 25 2026 - 22:52:18 EST


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>
---
drivers/input/joystick/cobra.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index ffa6d49c8..52331a947 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -180,8 +180,8 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
goto fail3;
}

- snprintf(cobra->phys[i], sizeof(cobra->phys[i]),
- "%s/input%d", gameport->phys, i);
+ scnprintf(cobra->phys[i], sizeof(cobra->phys[i]),
+ "%s/input%d", gameport->phys, i);

input_dev->name = "Creative Labs Blaster GamePad Cobra";
input_dev->phys = cobra->phys[i];