Linux Input/HID development
 help / color / mirror / Atom feed
* [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

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