The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] Input: cobra - use scnprintf() for the device physical path
@ 2026-11-26  3:52 Aibing Chen
  2026-11-26  5:48 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Aibing Chen @ 2026-11-26  3:52 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel

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@cmss.chinamobile.com>
---
 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];



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26  5:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  3:52 [PATCH] Input: cobra - use scnprintf() for the device physical path Aibing Chen
2026-11-26  5:48 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox