[PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path
From: Aibing Chen
Date: Thu Nov 26 2026 - 22:49:27 EST
sw_3dp_id() appends the PnP information to the caller's comment buffer
with snprintf(), and sw_connect() composes the physical path of each
device as "%s/input%d" from gameport->phys, which is a 32 byte string.
Both strings can be truncated, which is acceptable for informational
text, but with W=1 the file does not build:
drivers/input/joystick/sidewinder.c:538:58: error: '%s' directive
output may be truncated writing up to 8 bytes into a region of size
between 5 and 21 [-Werror=format-truncation=]
drivers/input/joystick/sidewinder.c:727:29: error: '/input' directive
output may be truncated writing 6 bytes into a region of size between
1 and 32 [-Werror=format-truncation=]
Use scnprintf() so that the writes are explicitly bounded and the file
builds warning free.
No functional change.
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
drivers/input/joystick/sidewinder.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 7f37d18c8..f6f76108d 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -535,7 +535,7 @@ static void sw_3dp_id(unsigned char *buf, char *comment, size_t size)
pnp[7] = rev[8] = 0;
- snprintf(comment, size, " [PnP %d.%02d id %s rev %s]",
+ scnprintf(comment, size, " [PnP %d.%02d id %s rev %s]",
(int) ((sw_get_bits(buf, 8, 6, 1) << 6) | /* Two 6-bit values */
sw_get_bits(buf, 16, 6, 1)) / 100,
(int) ((sw_get_bits(buf, 8, 6, 1) << 6) |
@@ -723,7 +723,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
snprintf(sw->name, sizeof(sw->name),
"Microsoft SideWinder %s", sw_name[sw->type]);
- snprintf(sw->phys[i], sizeof(sw->phys[i]),
+ scnprintf(sw->phys[i], sizeof(sw->phys[i]),
"%s/input%d", gameport->phys, i);
sw->dev[i] = input_dev = input_allocate_device();