From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] Input: joystick: use scnprintf() for the device physical paths
Date: Fri, 27 Nov 2026 11:49:03 +0800 [thread overview]
Message-ID: <20261127034904.288-1-chenaibing@cmss.chinamobile.com> (raw)
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;
next reply other threads:[~2026-11-27 3:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 3:49 Aibing Chen [this message]
2026-11-27 3:49 ` [PATCH 2/2] Input: sidewinder: use scnprintf() for the comment and physical path Aibing Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127034904.288-1-chenaibing@cmss.chinamobile.com \
--to=chenaibing@cmss.chinamobile.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®