[PATCH v3] Input: sidewinder - use scnprintf() for the port names
From: xujiahao
Date: Mon Nov 09 2026 - 21:00:42 EST
sw_connect() composes the physical path of each port as "%s/input%d"
from gameport->phys into a 32-byte array, and sw_3dp_id() builds
" [PnP %d.%02d id %s rev %s]" into the 40-byte comment buffer of
sw_connect(). GCC reports that both formats can overflow their buffers
in a W=1 build:
drivers/input/joystick/sidewinder.c:538:58: warning: '%s' directive output may be truncated writing up to 8 bytes into a region of size between 5 and 21 [-Wformat-truncation=]
drivers/input/joystick/sidewinder.c:727:29: warning: '/input' directive output may be truncated writing 6 bytes into a region of size between 1 and 32 [-Wformat-truncation=]
The values seen in practice fit these buffers, and a truncated name is
harmless, so keep the sizes as they are and switch to scnprintf() to
make the truncation explicit instead of letting the compiler warn about
a possible one.
Link: https://lore.kernel.org/all/20261106033300.3439313-1-xujiahao@xxxxxxxxxxxxxxxxxxxx/
Suggested-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202611091814.ChpgVgpE-lkp@xxxxxxxxx/
Closes: https://lore.kernel.org/oe-kbuild-all/202611100328.QAelfSpD-lkp@xxxxxxxxx/
Signed-off-by: xujiahao <xujiahao@xxxxxxxxxxxxxxxxxxxx>
---
v3:
- The PnP id computation is untouched again. v2 moved the (int) cast
behind the division, which made it a 64-bit division and broke 32-bit
builds (ld: undefined reference to __aeabi_uldivmod / __udivdi3 /
__umoddi3), as reported by the kernel test robot. Only the snprintf()
calls change now.
---
drivers/input/joystick/sidewinder.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 7f37d18c8..78dc70964 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -535,12 +535,12 @@ 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]",
- (int) ((sw_get_bits(buf, 8, 6, 1) << 6) | /* Two 6-bit values */
+ 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) |
+ (int)((sw_get_bits(buf, 8, 6, 1) << 6) |
sw_get_bits(buf, 16, 6, 1)) % 100,
- pnp, rev);
+ pnp, rev);
}
/*
@@ -723,8 +723,8 @@ 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]),
- "%s/input%d", gameport->phys, i);
+ scnprintf(sw->phys[i], sizeof(sw->phys[i]),
+ "%s/input%d", gameport->phys, i);
sw->dev[i] = input_dev = input_allocate_device();
if (!input_dev) {
--
2.43.0