* [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths
@ 2026-11-27 3:49 Aibing Chen
2026-11-27 3:49 ` [PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path Aibing Chen
2026-11-27 4:05 ` [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Aibing Chen @ 2026-11-27 3:49 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel
The joystick drivers compose the physical path of their input devices as
"%s/input%d" (or "%s/input0") from gameport->phys, which is a 32 byte
string, into buffers of the same size. The composed string can reach 39
bytes, so it does not fit: the path is informational and truncating it is
acceptable, but the call sites do not say so.
Because -Wformat-truncation is enabled for W=1 builds and COMPILE_TEST
configurations turn the warning into an error through CONFIG_WERROR,
these files do not build today, for example:
drivers/input/joystick/a3d.c:287:51: error: '/input0' directive output
may be truncated writing 7 bytes into a region of size between 1 and
32 [-Werror=format-truncation=]
Use scnprintf(), the helper that expresses a bounded, truncation tolerant
write, so that the files build warning free and the intent is visible at
the call sites.
No functional change.
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
drivers/input/joystick/a3d.c | 2 +-
drivers/input/joystick/analog.c | 2 +-
drivers/input/joystick/gf2k.c | 2 +-
drivers/input/joystick/grip.c | 2 +-
drivers/input/joystick/guillemot.c | 2 +-
drivers/input/joystick/interact.c | 2 +-
drivers/input/joystick/magellan.c | 2 +-
drivers/input/joystick/spaceball.c | 2 +-
drivers/input/joystick/spaceorb.c | 2 +-
drivers/input/joystick/tmdc.c | 2 +-
drivers/input/joystick/twidjoy.c | 2 +-
drivers/input/joystick/warrior.c | 2 +-
drivers/input/joystick/zhenhua.c | 2 +-
13 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 48a145796..d31de7c6c 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -284,7 +284,7 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_poll_handler(gameport, a3d_poll);
gameport_set_poll_interval(gameport, 20);
- snprintf(a3d->phys, sizeof(a3d->phys), "%s/input0", gameport->phys);
+ scnprintf(a3d->phys, sizeof(a3d->phys), "%s/input0", gameport->phys);
input_dev->name = a3d_names[a3d->mode];
input_dev->phys = a3d->phys;
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index b6f7bce1c..6bbe981e8 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -367,7 +367,7 @@ static int analog_init_device(struct analog_port *port, struct analog *analog, i
int error;
analog_name(analog);
- snprintf(analog->phys, sizeof(analog->phys),
+ scnprintf(analog->phys, sizeof(analog->phys),
"%s/input%d", port->gameport->phys, index);
analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn;
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 1d843115d..940dc8067 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -278,7 +278,7 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_poll_handler(gameport, gf2k_poll);
gameport_set_poll_interval(gameport, 20);
- snprintf(gf2k->phys, sizeof(gf2k->phys), "%s/input0", gameport->phys);
+ scnprintf(gf2k->phys, sizeof(gf2k->phys), "%s/input0", gameport->phys);
gf2k->length = gf2k_lens[gf2k->id];
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index 2a3f768a7..f685a62ca 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -333,7 +333,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
goto fail3;
}
- snprintf(grip->phys[i], sizeof(grip->phys[i]),
+ scnprintf(grip->phys[i], sizeof(grip->phys[i]),
"%s/input%d", gameport->phys, i);
input_dev->name = grip_name[grip->mode[i]];
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index 13f0fa4d3..d6771cef5 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -200,7 +200,7 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
gameport_set_poll_handler(gameport, guillemot_poll);
gameport_set_poll_interval(gameport, 20);
- snprintf(guillemot->phys, sizeof(guillemot->phys), "%s/input0", gameport->phys);
+ scnprintf(guillemot->phys, sizeof(guillemot->phys), "%s/input0", gameport->phys);
guillemot->type = guillemot_type + i;
input_dev->name = guillemot_type[i].name;
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index 507cec36b..d4961017d 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -229,7 +229,7 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
gameport_set_poll_handler(gameport, interact_poll);
gameport_set_poll_interval(gameport, 20);
- snprintf(interact->phys, sizeof(interact->phys), "%s/input0", gameport->phys);
+ scnprintf(interact->phys, sizeof(interact->phys), "%s/input0", gameport->phys);
interact->type = i;
interact->length = interact_type[i].length;
diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
index 201a049c8..61fcf0620 100644
--- a/drivers/input/joystick/magellan.c
+++ b/drivers/input/joystick/magellan.c
@@ -138,7 +138,7 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
magellan->dev = input_dev;
- snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
+ scnprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
input_dev->name = "LogiCad3D Magellan / SpaceMouse";
input_dev->phys = magellan->phys;
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index 1af299a41..cb536c6a0 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -205,7 +205,7 @@ static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
spaceball->dev = input_dev;
- snprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys);
+ scnprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys);
input_dev->name = spaceball_names[id];
input_dev->phys = spaceball->phys;
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index ba5b31899..a2a3d19db 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -153,7 +153,7 @@ static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
spaceorb->dev = input_dev;
- snprintf(spaceorb->phys, sizeof(spaceorb->phys), "%s/input0", serio->phys);
+ scnprintf(spaceorb->phys, sizeof(spaceorb->phys), "%s/input0", serio->phys);
input_dev->name = "SpaceTec SpaceOrb 360 / Avenger";
input_dev->phys = spaceorb->phys;
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index d419f41e6..b7457b3a6 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -294,7 +294,7 @@ static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
snprintf(port->name, sizeof(port->name), model->name,
port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode);
- snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i);
+ scnprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i);
port->dev = input_dev;
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index fb452552c..5d8a5081b 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -177,7 +177,7 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
twidjoy->dev = input_dev;
- snprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys);
+ scnprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys);
input_dev->name = "Handykey Twiddler";
input_dev->phys = twidjoy->phys;
diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c
index 2e1c6df98..119402782 100644
--- a/drivers/input/joystick/warrior.c
+++ b/drivers/input/joystick/warrior.c
@@ -130,7 +130,7 @@ static int warrior_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
warrior->dev = input_dev;
- snprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys);
+ scnprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys);
input_dev->name = "Logitech WingMan Warrior";
input_dev->phys = warrior->phys;
diff --git a/drivers/input/joystick/zhenhua.c b/drivers/input/joystick/zhenhua.c
index 8ca189663..d38ab4ea2 100644
--- a/drivers/input/joystick/zhenhua.c
+++ b/drivers/input/joystick/zhenhua.c
@@ -137,7 +137,7 @@ static int zhenhua_connect(struct serio *serio, struct serio_driver *drv)
goto fail1;
zhenhua->dev = input_dev;
- snprintf(zhenhua->phys, sizeof(zhenhua->phys), "%s/input0", serio->phys);
+ scnprintf(zhenhua->phys, sizeof(zhenhua->phys), "%s/input0", serio->phys);
input_dev->name = "Zhen Hua 5-byte device";
input_dev->phys = zhenhua->phys;
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path
2026-11-27 3:49 [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths Aibing Chen
@ 2026-11-27 3:49 ` Aibing Chen
2026-11-27 4:05 ` [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Aibing Chen @ 2026-11-27 3:49 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel
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@cmss.chinamobile.com>
---
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();
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths
2026-11-27 3:49 [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths Aibing Chen
2026-11-27 3:49 ` [PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path Aibing Chen
@ 2026-11-27 4:05 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-27 4:05 UTC (permalink / raw)
To: Aibing Chen; +Cc: linux-input, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] Input: joystick: cobra and stinger physical paths still use
snprintf()
--
commit dad6d0895b43b6671b115696abcf12d42b3f99fb
Author: Aibing Chen <chenaibing@cmss.chinamobile.com>
Input: joystick: use scnprintf() for the device physical paths
This commit switches thirteen joystick drivers from snprintf() to
scnprintf() when formatting input device physical paths to silence W=1
-Wformat-truncation warnings.
> diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
> index 2a3f768a72186..f685a62cad6de 100644
> --- a/drivers/input/joystick/grip.c
> +++ b/drivers/input/joystick/grip.c
> @@ -333,7 +333,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
> goto fail3;
> }
>
> - snprintf(grip->phys[i], sizeof(grip->phys[i]),
> + scnprintf(grip->phys[i], sizeof(grip->phys[i]),
> "%s/input%d", gameport->phys, i);
>
> input_dev->name = grip_name[grip->mode[i]];
> diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
> index 201a049c8c06b..61fcf0620937c 100644
> --- a/drivers/input/joystick/magellan.c
> +++ b/drivers/input/joystick/magellan.c
> @@ -138,7 +138,7 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
> goto fail1;
>
> magellan->dev = input_dev;
> - snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
> + scnprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
>
> input_dev->name = "LogiCad3D Magellan / SpaceMouse";
> input_dev->phys = magellan->phys;
[Severity: Low]
Should cobra_connect() in drivers/input/joystick/cobra.c and
stinger_connect() in drivers/input/joystick/stinger.c also be converted to
scnprintf()?
They format 32-byte gameport->phys and serio->phys strings into 32-byte
phys buffers with snprintf() and hit the same W=1 -Wformat-truncation
error under CONFIG_WERROR:
drivers/input/joystick/cobra.c:cobra_connect() {
...
snprintf(cobra->phys[i], sizeof(cobra->phys[i]),
"%s/input%d", gameport->phys, i);
...
}
drivers/input/joystick/stinger.c:stinger_connect() {
...
snprintf(stinger->phys, sizeof(stinger->phys), "%s/serio0", serio->phys);
...
}
Also, the commit message says the drivers compose their physical path from
gameport->phys, whereas six of the modified drivers (magellan, spaceball,
spaceorb, twidjoy, warrior, and zhenhua) compose it from serio->phys.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127034904.288-1-chenaibing@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 4:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 3:49 [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths Aibing Chen
2026-11-27 3:49 ` [PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path Aibing Chen
2026-11-27 4:05 ` [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox