Input: replace strlcat() with strscpy() in USB input drivers
Subsystems (6)
cover Input: replace strlcat() with strscpy() in USB input drivers
Several USB input drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API [1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
The series is split by input subdirectory:
1/5: joystick drivers (pxrc, xpad)
2/5: misc drivers (ati_remote2, cm109, ims-pcu, keyspan_remote,
powermate, yealink)
3/5: mouse drivers (appletouch, bcm5974, synaptics_usb) 4/5: tablet drivers (acecad, aiptek, hanwang, kbtab,
pegasus_notetaker)
5/5: touchscreen drivers (sur40, usbtouchscreen)
---
Shihuang Liu (5):
Input: joystick - replace strlcat() with strscpy()
Input: misc - replace strlcat() with strscpy()
Input: mouse - replace strlcat() with strscpy()
Input: tablet - replace strlcat() with strscpy()
Input: touchscreen - replace strlcat() with strscpy()
drivers/input/joystick/pxrc.c | 4 +++- drivers/input/joystick/xpad.c | 4 +++- drivers/input/misc/ati_remote2.c | 4 +++- drivers/input/misc/cm109.c | 4 +++- drivers/input/misc/ims-pcu.c | 8 ++++++-- drivers/input/misc/keyspan_remote.c | 4 +++- drivers/input/misc/powermate.c | 4 +++- drivers/input/misc/yealink.c | 4 +++- drivers/input/mouse/appletouch.c | 4 +++- drivers/input/mouse/bcm5974.c | 4 +++- drivers/input/mouse/synaptics_usb.c | 4 +++- drivers/input/tablet/acecad.c | 4 +++- drivers/input/tablet/aiptek.c | 7 +++++-- drivers/input/tablet/hanwang.c | 4 +++- drivers/input/tablet/kbtab.c | 4 +++- drivers/input/tablet/pegasus_notetaker.c | 4 +++- drivers/input/touchscreen/sur40.c | 4 +++- drivers/input/touchscreen/usbtouchscreen.c | 4 +++- 18 files changed, 59 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/5 Input: joystick - replace strlcat() with strscpy()
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API[1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
--- drivers/input/joystick/pxrc.c | 4 +++- drivers/input/joystick/xpad.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/input/joystick/pxrc.c +3 -1
@@ -121,6 +121,7 @@ static int pxrc_probe(struct usb_interface *intf,struct pxrc *pxrc;struct usb_endpoint_descriptor *epirq;size_t xfer_size; +size_t len;void *xfer_buf;int error;
@@ -170,7 +171,8 @@ static int pxrc_probe(struct usb_interface *intf, pxrc->input->name ="PXRC Flight Controller Adapter" ;usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len); pxrc->input->phys = pxrc->phys;usb_to_input_id (udev, &pxrc->input->id);
drivers/input/joystick/xpad.c +3 -1
@@ -2045,6 +2045,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *idstruct usb_xpad *xpad;struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;int i, error; +size_t len;if (intf->cur_altsetting->desc.bNumEndpoints !=2 )return -ENODEV ;
@@ -2060,7 +2061,8 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *idreturn -ENOMEM ;usb_make_path (udev, xpad->phys,sizeof (xpad->phys)); -strlcat (xpad->phys,"/input0" ,sizeof (xpad->phys)); + len =strnlen (xpad->phys,sizeof (xpad->phys)); +strscpy (xpad->phys + len,"/input0" ,sizeof (xpad->phys) - len); xpad->idata =usb_alloc_coherent (udev,XPAD_PKT_LEN ,GFP_KERNEL , &xpad->idata_dma);
Signature · 1 line
2.43.0
Dmitry Torokhov
maintainerRe: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Hi Shihuang,
Quoted 7 lines · Shihuang Liu
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with
strlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
...
drivers/input/joystick/pxrc.c static int pxrc_probe(struct usb_interface *intf, · line 175
Quoted 4 lines
drivers/input/joystick/pxrc.c +2
-1usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len);
I really dislike this conversion pattern, and I do not want to see it open-coded across 18 drivers in this series.
usb_make_path() is just a trivial wrapper around snprintf() that already returns the length of the formatted string. Calling usb_make_path(), ignoring its return value, rescanning the buffer with strnlen(), and then open-coding pointer and size arithmetic for strscpy() (along with an extra local variable in every probe function) makes the code much uglier and harder to read than what we had before.
All of these USB input drivers already include <linux/usb/input.h>, and drivers across other subsystems (drivers/hid/usbhid/, drivers/media/rc/, drivers/media/usb/, sound/usb/caiaq/, drivers/usb/storage/onetouch.c) all use the exact same usb_make_path() + suffix pattern ("/input0", "/input%d", "/ir0", "/button", etc.).
If we want to get rid of strlcat() here, please introduce a generic helper in include/linux/usb.h (or a USB input helper in include/linux/usb/input.h) that formats the USB path together with the subpath in a single pass, for example:
__printf(4, 5)
int usb_make_subpath(struct usb_device *dev, char *buf, size_t size,
const char *fmt, ...);
(or a simple const char *suffix variant if formatting is not needed). Then each driver can do:
usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");
and even drivers/hid/usbhid/hid-core.c can simply do:
usb_make_subpath(dev, hid->phys, sizeof(hid->phys), "input%d", intf->altsetting[0].desc.bInterfaceNumber);
instead of repeating this strnlen() + strscpy() boilerplate everywhere.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Quoted 44 lines · Dmitry Torokhov
Hi Shihuang,
Quoted 7 lines · Shihuang Liu
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with
strlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers....
drivers/input/joystick/pxrc.c static int pxrc_probe(struct usb_interface *intf, · line 175
Quoted 4 lines
drivers/input/joystick/pxrc.c +2
-1usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len);I really dislike this conversion pattern, and I do not want to see it open-coded across 18 drivers in this series.
usb_make_path()is just a trivial wrapper aroundsnprintf()that already returns the length of the formatted string. Callingusb_make_path(), ignoring its return value, rescanning the buffer withstrnlen(), and then open-coding pointer and size arithmetic forstrscpy()(along with an extra local variable in every probe function) makes the code much uglier and harder to read than what we had before.All of these USB input drivers already include <
linux/usb/input.h>, and drivers across other subsystems (drivers/hid/usbhid/,drivers/media/rc/,drivers/media/usb/,sound/usb/caiaq/,drivers/usb/storage/onetouch.c) all use the exact sameusb_make_path()+ suffix pattern ("/input0", "/input%d", "/ir0", "/button", etc.).If we want to get rid of
strlcat()here, please introduce a generic helper ininclude/linux/usb.h(or a USB input helper ininclude/linux/usb/input.h) that formats the USB path together with the subpath in a single pass, for example:
__printf(4, 5)
int usb_make_subpath(structusb_device*dev, char *buf,size_tsize,const char *fmt, ...);(or a simple const char *suffix variant if formatting is not needed). Then each driver can do:
Quoted 8 lines
usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");and even
drivers/hid/usbhid/hid-core.ccan simply do:usb_make_subpath(dev, hid->phys, sizeof(hid->phys), "input%d", intf->altsetting[0].desc.bInterfaceNumber);instead of repeating this
strnlen()+strscpy()boilerplate everywhere.
I'm all for that too, and putting it in the USB core for everyone to use would be great.
thanks,
greg k-h
Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Quoted 49 lines · Greg KH
Quoted 48 lines · Dmitry Torokhov
Hi Shihuang,
Quoted 7 lines · Shihuang Liu
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with
strlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers....
drivers/input/joystick/pxrc.c static int pxrc_probe(struct usb_interface *intf, · line 175
Quoted 4 lines
drivers/input/joystick/pxrc.c +2
-1usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len);I really dislike this conversion pattern, and I do not want to see it open-coded across 18 drivers in this series.
usb_make_path()is just a trivial wrapper aroundsnprintf()that already returns the length of the formatted string. Callingusb_make_path(), ignoring its return value, rescanning the buffer withstrnlen(), and then open-coding pointer and size arithmetic forstrscpy()(along with an extra local variable in every probe function) makes the code much uglier and harder to read than what we had before.All of these USB input drivers already include <
linux/usb/input.h>, and drivers across other subsystems (drivers/hid/usbhid/,drivers/media/rc/,drivers/media/usb/,sound/usb/caiaq/,drivers/usb/storage/onetouch.c) all use the exact sameusb_make_path()+ suffix pattern ("/input0", "/input%d", "/ir0", "/button", etc.).If we want to get rid of
strlcat()here, please introduce a generic helper ininclude/linux/usb.h(or a USB input helper ininclude/linux/usb/input.h) that formats the USB path together with the subpath in a single pass, for example:
__printf(4, 5)
int usb_make_subpath(structusb_device*dev, char *buf,size_tsize,const char *fmt, ...);(or a simple const char *suffix variant if formatting is not needed). Then each driver can do:
usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");and even
drivers/hid/usbhid/hid-core.ccan simply do:
Quoted 7 lines
Quoted 4 lines
usb_make_subpath(dev, hid->phys, sizeof(hid->phys), "input%d", intf->altsetting[0].desc.bInterfaceNumber);instead of repeating this
strnlen()+strscpy()boilerplate everywhere.I'm all for that too, and putting it in the USB core for everyone to use would be great.
Hi Dmitry, Greg,
Thanks for the suggestions and review. I'll respin the series on top of a new helper in USB core.
Thanks.
--
Shihuang Liu
Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
In reply to Greg KHHi Greg,
Quoted 52 lines
Date: 2026-10-17 10:19:59+0200
From: Greg KH <[email protected]>Quoted 48 lines · Dmitry Torokhov
Hi Shihuang,
Quoted 7 lines · Shihuang Liu
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with
strlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers....
drivers/input/joystick/pxrc.c static int pxrc_probe(struct usb_interface *intf, · line 175
Quoted 4 lines
drivers/input/joystick/pxrc.c +2
-1usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len);I really dislike this conversion pattern, and I do not want to see it open-coded across 18 drivers in this series.
usb_make_path()is just a trivial wrapper aroundsnprintf()that already returns the length of the formatted string. Callingusb_make_path(), ignoring its return value, rescanning the buffer withstrnlen(), and then open-coding pointer and size arithmetic forstrscpy()(along with an extra local variable in every probe function) makes the code much uglier and harder to read than what we had before.All of these USB input drivers already include <
linux/usb/input.h>, and drivers across other subsystems (drivers/hid/usbhid/,drivers/media/rc/,drivers/media/usb/,sound/usb/caiaq/,drivers/usb/storage/onetouch.c) all use the exact sameusb_make_path()+ suffix pattern ("/input0", "/input%d", "/ir0", "/button", etc.).If we want to get rid of
strlcat()here, please introduce a generic helper ininclude/linux/usb.h(or a USB input helper ininclude/linux/usb/input.h) that formats the USB path together with the subpath in a single pass, for example:
__printf(4, 5)
int usb_make_subpath(structusb_device*dev, char *buf,size_tsize,const char *fmt, ...);(or a simple const char *suffix variant if formatting is not needed). Then each driver can do:
usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");and even
drivers/hid/usbhid/hid-core.ccan simply do:
Quoted 7 lines
Quoted 4 lines
usb_make_subpath(dev, hid->phys, sizeof(hid->phys), "input%d", intf->altsetting[0].desc.bInterfaceNumber);instead of repeating this
strnlen()+strscpy()boilerplate everywhere.I'm all for that too, and putting it in the USB core for everyone to use would be great.
You might be interested in <https://lore.kernel.org/linux-hardening/[email protected]/>.
I was working on something like that, but actually much simpler.
It is meant to replace strscpy()/snprintf() by versions more similar to
Plan9's strecpy(2)/seprint(2), but without some important flaw that the
Plan9 APIs have (about handling NULL).
Have a lovely day!
Alex
Quoted 5 lines
thanks,
greg k-h
Signature · 1 line
<https://www.alejandro-colomar.es>
Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Quoted 59 lines · Alejandro Colomar
Hi Greg,
Quoted 57 lines
Date: 2026-10-17 10:19:59+0200
From: Greg KH <[email protected]>Quoted 52 lines · Dmitry Torokhov
Hi Shihuang,
Quoted 7 lines · Shihuang Liu
The pxrc and xpad drivers build the physical path by appending a constant "/input0" suffix with
strlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers....
drivers/input/joystick/pxrc.c static int pxrc_probe(struct usb_interface *intf, · line 175
Quoted 4 lines
drivers/input/joystick/pxrc.c +2
-1usb_make_path (udev, pxrc->phys,sizeof (pxrc->phys)); -strlcat (pxrc->phys,"/input0" ,sizeof (pxrc->phys)); + len =strnlen (pxrc->phys,sizeof (pxrc->phys)); +strscpy (pxrc->phys + len,"/input0" ,sizeof (pxrc->phys) - len);I really dislike this conversion pattern, and I do not want to see it open-coded across 18 drivers in this series.
usb_make_path()is just a trivial wrapper aroundsnprintf()that already returns the length of the formatted string. Callingusb_make_path(), ignoring its return value, rescanning the buffer withstrnlen(), and then open-coding pointer and size arithmetic forstrscpy()(along with an extra local variable in every probe function) makes the code much uglier and harder to read than what we had before.All of these USB input drivers already include <
linux/usb/input.h>, and drivers across other subsystems (drivers/hid/usbhid/,drivers/media/rc/,drivers/media/usb/,sound/usb/caiaq/,drivers/usb/storage/onetouch.c) all use the exact sameusb_make_path()+ suffix pattern ("/input0", "/input%d", "/ir0", "/button", etc.).If we want to get rid of
strlcat()here, please introduce a generic helper ininclude/linux/usb.h(or a USB input helper ininclude/linux/usb/input.h) that formats the USB path together with the subpath in a single pass, for example:
__printf(4, 5)
int usb_make_subpath(structusb_device*dev, char *buf,size_tsize,const char *fmt, ...);(or a simple const char *suffix variant if formatting is not needed). Then each driver can do:
usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");and even
drivers/hid/usbhid/hid-core.ccan simply do:usb_make_subpath(dev, hid->phys, sizeof(hid->phys), "input%d", intf->altsetting[0].desc.bInterfaceNumber);instead of repeating this
strnlen()+strscpy()boilerplate everywhere.
Quoted 8 lines
Quoted 2 lines
I'm all for that too, and putting it in the USB core for everyone to use would be great.
You might be interested in <https://lore.kernel.org/linux-hardening/[email protected]/>.
I was working on something like that, but actually much simpler.
It is meant to replace strscpy()/snprintf() by versions more similar to
Plan9's strecpy(2)/seprint(2), but without some important flaw that the
Plan9 APIs have (about handling NULL).
Look at the patches from Kees on the hardening list for the seqbuf stuff, that ideally will replace these types of string functions entirely over time.
thanks,
greg k-h
Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Hi Greg,
Quoted 3 lines
Date: 2026-10-19 10:44:22+0200
From: Greg KH <[email protected]>
[...]
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
I'm all for that too, and putting it in the USB core for everyone to use would be great.
You might be interested in <https://lore.kernel.org/linux-hardening/[email protected]/>.
I was working on something like that, but actually much simpler.
It is meant to replace strscpy()/snprintf() by versions more similar to
Plan9's strecpy(2)/seprint(2), but without some important flaw that the
Plan9 APIs have (about handling NULL).
Quoted 3 lines
Look at the patches from Kees on the hardening list for the seqbuf stuff, that ideally will replace these types of string functions entirely over time.
I have looked at them. I personally think some of them are a bit unnecessarily complex, by being designed around lengths instead of offset pointers.
Essentially, his API is a wrapper around the usual strscpy()/snprintf(3) operations, but because those fundamental operations are themselves flawed, their wrapper is inherently flawed too. stpecpy()/seprintf() are the same, but are simpler to use raw, and by being simpler to use, their wrappers would naturally because also simpler.
I'm trying to convince Kees of this. :-)
Have a lovely night!
Alex
Quoted 4 lines
thanks,
greg k-h
Signature · 1 line
<https://www.alejandro-colomar.es>
PATCH 2/5 Input: misc - replace strlcat() with strscpy()
In reply to Shihuang LiuThe ati_remote2, cm109, ims-pcu, keyspan_remote, powermate and yealink drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API[1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
--- drivers/input/misc/ati_remote2.c | 4 +++- drivers/input/misc/cm109.c | 4 +++- drivers/input/misc/ims-pcu.c | 8 ++++++-- drivers/input/misc/keyspan_remote.c | 4 +++- drivers/input/misc/powermate.c | 4 +++- drivers/input/misc/yealink.c | 4 +++- 6 files changed, 21 insertions(+), 7 deletions(-)
drivers/input/misc/ati_remote2.c +3 -1
@@ -767,6 +767,7 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_dstruct usb_device *udev =interface_to_usbdev (interface);struct usb_host_interface *alt = interface->cur_altsetting;struct ati_remote2 *ar2; +size_t len;int r;if (alt->desc.bInterfaceNumber)
@@ -823,7 +824,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d goto fail3;usb_make_path (udev, ar2->phys,sizeof (ar2->phys)); -strlcat (ar2->phys,"/input0" ,sizeof (ar2->phys)); + len =strnlen (ar2->phys,sizeof (ar2->phys)); +strscpy (ar2->phys + len,"/input0" ,sizeof (ar2->phys) - len);strlcat (ar2->name,"ATI Remote Wonder II" ,sizeof (ar2->name));
drivers/input/misc/cm109.c +3 -1
@@ -685,6 +685,7 @@ static int cm109_usb_probe(struct usb_interface *intf,struct input_dev *input_dev =NULL ;int ret, pipe, i;int error = -ENOMEM ; +size_t len; interface = intf->cur_altsetting;
@@ -766,7 +767,8 @@ static int cm109_usb_probe(struct usb_interface *intf,/* find out the physical bus location */ usb_make_path (udev, dev->phys,sizeof (dev->phys)); -strlcat (dev->phys,"/input0" ,sizeof (dev->phys)); + len =strnlen (dev->phys,sizeof (dev->phys)); +strscpy (dev->phys + len,"/input0" ,sizeof (dev->phys) - len);/* register settings for the input device */ input_dev->name = nfo->name;
drivers/input/misc/ims-pcu.c +6 -2
@@ -205,6 +205,7 @@ static int ims_pcu_setup_buttons(struct ims_pcu *pcu,struct input_dev *input;int i;int error; +size_t len; input =input_allocate_device ();if (!input) {
@@ -216,7 +217,8 @@ static int ims_pcu_setup_buttons(struct ims_pcu *pcu, "IMS PCU#%d Button Interface", pcu->device_no);usb_make_path (pcu->udev, buttons->phys,sizeof (buttons->phys)); -strlcat (buttons->phys,"/input0" ,sizeof (buttons->phys)); + len =strnlen (buttons->phys,sizeof (buttons->phys)); +strscpy (buttons->phys + len,"/input0" ,sizeof (buttons->phys) - len);memcpy (buttons->keymap, keymap,sizeof (*keymap) * keymap_len);
@@ -286,6 +288,7 @@ static int ims_pcu_setup_gamepad(struct ims_pcu *pcu)struct ims_pcu_gamepad *gamepad;struct input_dev *input;int error; +size_t len; gamepad =kzalloc_obj (*gamepad); input =input_allocate_device ();
@@ -302,7 +305,8 @@ static int ims_pcu_setup_gamepad(struct ims_pcu *pcu) "IMS PCU#%d Gamepad Interface", pcu->device_no);usb_make_path (pcu->udev, gamepad->phys,sizeof (gamepad->phys)); -strlcat (gamepad->phys,"/input1" ,sizeof (gamepad->phys)); + len =strnlen (gamepad->phys,sizeof (gamepad->phys)); +strscpy (gamepad->phys + len,"/input1" ,sizeof (gamepad->phys) - len); input->name = gamepad->name; input->phys = gamepad->phys;
drivers/input/misc/keyspan_remote.c +3 -1
@@ -430,6 +430,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devicstruct usb_keyspan *remote;struct input_dev *input_dev;int i, error; +size_t len; error =usb_find_int_in_endpoint (interface->cur_altsetting, &endpoint);if (error)
@@ -482,7 +483,8 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic le16_to_cpu(udev->descriptor.idProduct));usb_make_path (udev, remote->phys,sizeof (remote->phys)); -strlcat (remote->phys,"/input0" ,sizeof (remote->phys)); + len =strnlen (remote->phys,sizeof (remote->phys)); +strscpy (remote->phys + len,"/input0" ,sizeof (remote->phys) - len);memcpy (remote->keymap, keyspan_key_table,sizeof (remote->keymap)); input_dev->name = remote->name;
drivers/input/misc/powermate.c +3 -1
@@ -299,6 +299,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_istruct input_dev *input_dev;int pipe, maxp;int error = -ENOMEM ; +size_t len; interface = intf->cur_altsetting;if (interface->desc.bNumEndpoints <1 )
@@ -334,7 +335,8 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i pm->input = input_dev;usb_make_path (udev, pm->phys,sizeof (pm->phys)); -strlcat (pm->phys,"/input0" ,sizeof (pm->phys)); + len =strnlen (pm->phys,sizeof (pm->phys)); +strscpy (pm->phys + len,"/input0" ,sizeof (pm->phys) - len);spin_lock_init (&pm->lock);
drivers/input/misc/yealink.c +3 -1
@@ -812,6 +812,7 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)struct yealink_dev *yld;struct input_dev *input_dev;int ret, pipe, i; +size_t len; interface = intf->cur_altsetting;
@@ -891,7 +892,8 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)/* find out the physical bus location */ usb_make_path (udev, yld->phys,sizeof (yld->phys)); -strlcat (yld->phys,"/input0" ,sizeof (yld->phys)); + len =strnlen (yld->phys,sizeof (yld->phys)); +strscpy (yld->phys + len,"/input0" ,sizeof (yld->phys) - len);/* register settings for the input device */ input_dev->name = nfo->name;
Signature · 1 line
2.43.0
Re: [PATCH 2/5] Input: misc - replace strlcat() with strscpy()
Hi Shihuang,
Quoted 37 lines
Date: 2026-10-17 01:04:08+0800
From: Shihuang Liu <[email protected]>The
ati_remote2, cm109, ims-pcu,keyspan_remote, powermate and yealink drivers build the physical path by appending a constant "/input0" suffix withstrlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.Signed-off-by Shihuang Liu <[email protected]>---
drivers/input/misc/ati_remote2.c | 4 +++- drivers/input/misc/cm109.c | 4 +++- drivers/input/misc/ims-pcu.c | 8 ++++++-- drivers/input/misc/keyspan_remote.c | 4 +++- drivers/input/misc/powermate.c | 4 +++- drivers/input/misc/yealink.c | 4 +++- 6 files changed, 21 insertions(+), 7 deletions(-)drivers/input/misc/ati_remote2.c +1
-0@@ -767,6 +767,7 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_dstruct usb_device *udev =interface_to_usbdev (interface);struct usb_host_interface *alt = interface->cur_altsetting;struct ati_remote2 *ar2; +size_t len;int r;if (alt->desc.bInterfaceNumber)
drivers/input/misc/ati_remote2.c static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d · line 827
Quoted 5 lines
drivers/input/misc/ati_remote2.c +1
-1@@ -823,7 +824,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d goto fail3;usb_make_path (udev, ar2->phys,sizeof (ar2->phys)); -strlcat (ar2->phys,"/input0" ,sizeof (ar2->phys)); + len =strnlen (ar2->phys,sizeof (ar2->phys));
Why strnlen(3)? ar2->phys should be a string, right? If it is not, then we'd already have a buffer overread in strlcat(3), and then the commit should be reporting a bug fix. This should use strlen(3) instead.
drivers/input/misc/ati_remote2.c static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d · line 828
Quoted 1 line
drivers/input/misc/ati_remote2.c +1
-0+strscpy (ar2->phys + len,"/input0" ,sizeof (ar2->phys) - len);
NAKing this. This is precisely what strlcat(3)'s documentation in OpenBSD says you shouldn't do:
Since it is known how many characters were copied the first time, things can be sped up a bit by using a copy instead of an append: char *dir, *file, pname[PATH_MAX]; size_t n; ... n = strlcpy(pname, dir, sizeof(pname)); if (n >= sizeof(pname)) goto toolong; if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) goto toolong; However, one may question the validity of such optimizations, as they defeat the whole purpose of strlcpy() and strlcat(). As a matter of fact, the first version of this manual page got it wrong.
<https://man.openbsd.org/strlcpy>
The right approach is to have a function that does the right thing. There are two viable alternatives:
- Write strscat(). It would take the strlen() internally, and so it would be unnecessarily inefficient. Prefer the next one.
- Write stpecpy(). It returns a pointer, which allows chaining easily.
Here's a viable implementation of stpecpy():
char *
stpecpy(char *dst, const char end[0], const char *restrict src)
{
ssize_t dlen;
if (dst == NULL)
return NULL;
dlen = strscpy(dst, src, end - dst);
if (dlen < 0)
return NULL;
return dst + dlen;
}This would need to be accompanied by a seprintf() too, which would be used by usb_make_path() to produce a pointer suitable for chaining. I've been working on adding those.
If you want to keep it easy, I'd do strscat(). We can modify it later to be more efficient. After all, we already have the inefficiency of calling strlcat(3) now.
Have a lovely day!
Alex
Quoted 134 lines
drivers/input/misc/ati_remote2.c +0
-0strlcat (ar2->name,"ATI Remote Wonder II" ,sizeof (ar2->name));drivers/input/misc/cm109.c +3
-1@@ -685,6 +685,7 @@ static int cm109_usb_probe(struct usb_interface *intf,struct input_dev *input_dev =NULL ;int ret, pipe, i;int error = -ENOMEM ; +size_t len; interface = intf->cur_altsetting;@@ -766,7 +767,8 @@ static int cm109_usb_probe(struct usb_interface *intf,/* find out the physical bus location */ usb_make_path (udev, dev->phys,sizeof (dev->phys)); -strlcat (dev->phys,"/input0" ,sizeof (dev->phys)); + len =strnlen (dev->phys,sizeof (dev->phys)); +strscpy (dev->phys + len,"/input0" ,sizeof (dev->phys) - len);/* register settings for the input device */ input_dev->name = nfo->name;drivers/input/misc/ims-pcu.c +6
-2@@ -205,6 +205,7 @@ static int ims_pcu_setup_buttons(struct ims_pcu *pcu,struct input_dev *input;int i;int error; +size_t len; input =input_allocate_device ();if (!input) {@@ -216,7 +217,8 @@ static int ims_pcu_setup_buttons(struct ims_pcu *pcu, "IMS PCU#%d Button Interface", pcu->device_no);usb_make_path (pcu->udev, buttons->phys,sizeof (buttons->phys)); -strlcat (buttons->phys,"/input0" ,sizeof (buttons->phys)); + len =strnlen (buttons->phys,sizeof (buttons->phys)); +strscpy (buttons->phys + len,"/input0" ,sizeof (buttons->phys) - len);memcpy (buttons->keymap, keymap,sizeof (*keymap) * keymap_len);@@ -286,6 +288,7 @@ static int ims_pcu_setup_gamepad(struct ims_pcu *pcu)struct ims_pcu_gamepad *gamepad;struct input_dev *input;int error; +size_t len; gamepad =kzalloc_obj (*gamepad); input =input_allocate_device ();@@ -302,7 +305,8 @@ static int ims_pcu_setup_gamepad(struct ims_pcu *pcu) "IMS PCU#%d Gamepad Interface", pcu->device_no);usb_make_path (pcu->udev, gamepad->phys,sizeof (gamepad->phys)); -strlcat (gamepad->phys,"/input1" ,sizeof (gamepad->phys)); + len =strnlen (gamepad->phys,sizeof (gamepad->phys)); +strscpy (gamepad->phys + len,"/input1" ,sizeof (gamepad->phys) - len); input->name = gamepad->name; input->phys = gamepad->phys;drivers/input/misc/keyspan_remote.c +3
-1@@ -430,6 +430,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devicstruct usb_keyspan *remote;struct input_dev *input_dev;int i, error; +size_t len; error =usb_find_int_in_endpoint (interface->cur_altsetting, &endpoint);if (error)@@ -482,7 +483,8 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic le16_to_cpu(udev->descriptor.idProduct));usb_make_path (udev, remote->phys,sizeof (remote->phys)); -strlcat (remote->phys,"/input0" ,sizeof (remote->phys)); + len =strnlen (remote->phys,sizeof (remote->phys)); +strscpy (remote->phys + len,"/input0" ,sizeof (remote->phys) - len);memcpy (remote->keymap, keyspan_key_table,sizeof (remote->keymap)); input_dev->name = remote->name;drivers/input/misc/powermate.c +3
-1@@ -299,6 +299,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_istruct input_dev *input_dev;int pipe, maxp;int error = -ENOMEM ; +size_t len; interface = intf->cur_altsetting;if (interface->desc.bNumEndpoints <1 )@@ -334,7 +335,8 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i pm->input = input_dev;usb_make_path (udev, pm->phys,sizeof (pm->phys)); -strlcat (pm->phys,"/input0" ,sizeof (pm->phys)); + len =strnlen (pm->phys,sizeof (pm->phys)); +strscpy (pm->phys + len,"/input0" ,sizeof (pm->phys) - len);spin_lock_init (&pm->lock);drivers/input/misc/yealink.c +3
-1@@ -812,6 +812,7 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)struct yealink_dev *yld;struct input_dev *input_dev;int ret, pipe, i; +size_t len; interface = intf->cur_altsetting;@@ -891,7 +892,8 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)/* find out the physical bus location */ usb_make_path (udev, yld->phys,sizeof (yld->phys)); -strlcat (yld->phys,"/input0" ,sizeof (yld->phys)); + len =strnlen (yld->phys,sizeof (yld->phys)); +strscpy (yld->phys + len,"/input0" ,sizeof (yld->phys) - len);/* register settings for the input device */ input_dev->name = nfo->name;Signature · 1 line
2.43.0
Signature · 1 line
<https://www.alejandro-colomar.es>
Re: [PATCH 2/5] Input: misc - replace strlcat() with strscpy()
Quoted 102 lines · Alejandro Colomar
Hi Shihuang,
Quoted 37 lines
Date: 2026-10-17 01:04:08+0800
From: Shihuang Liu <[email protected]>The
ati_remote2, cm109, ims-pcu,keyspan_remote, powermate and yealink drivers build the physical path by appending a constant "/input0" suffix withstrlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.Signed-off-by Shihuang Liu <[email protected]>---
drivers/input/misc/ati_remote2.c | 4 +++- drivers/input/misc/cm109.c | 4 +++- drivers/input/misc/ims-pcu.c | 8 ++++++-- drivers/input/misc/keyspan_remote.c | 4 +++- drivers/input/misc/powermate.c | 4 +++- drivers/input/misc/yealink.c | 4 +++- 6 files changed, 21 insertions(+), 7 deletions(-)drivers/input/misc/ati_remote2.c +1
-0@@ -767,6 +767,7 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_dstruct usb_device *udev =interface_to_usbdev (interface);struct usb_host_interface *alt = interface->cur_altsetting;struct ati_remote2 *ar2; +size_t len;int r;if (alt->desc.bInterfaceNumber)drivers/input/misc/ati_remote2.c static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d · line 827
Quoted 5 lines
drivers/input/misc/ati_remote2.c +1
-1@@ -823,7 +824,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d goto fail3;usb_make_path (udev, ar2->phys,sizeof (ar2->phys)); -strlcat (ar2->phys,"/input0" ,sizeof (ar2->phys)); + len =strnlen (ar2->phys,sizeof (ar2->phys));Why strnlen(3)?
ar2->physshould be a string, right? If it is not, then we'd already have a buffer overread in strlcat(3), and then the commit should be reporting a bug fix. This should use strlen(3) instead.drivers/input/misc/ati_remote2.c static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d · line 828
Quoted 1 line
drivers/input/misc/ati_remote2.c +1
-0+strscpy (ar2->phys + len,"/input0" ,sizeof (ar2->phys) - len);NAKing this. This is precisely what strlcat(3)'s documentation in OpenBSD says you shouldn't do:
Since it is known how many characters were copied the first time, things can be sped up a bit by using a copy instead of an append: char *dir, *file, pname[PATH_MAX]; size_t n; ... n = strlcpy(pname, dir, sizeof(pname)); if (n >= sizeof(pname)) goto toolong; if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) goto toolong; However, one may question the validity of such optimizations, as they defeat the whole purpose of strlcpy() and strlcat(). As a matter of fact, the first version of this manual page got it wrong.<https://man.openbsd.org/strlcpy>
The right approach is to have a function that does the right thing. There are two viable alternatives:
(quoted diff) +0
-2- Write strscat(). It would take the strlen() internally, and so it would be unnecessarily inefficient. Prefer the next one. - Write stpecpy(). It returns a pointer, which allows chaining easily.Here's a viable implementation of
stpecpy():char * stpecpy(char *dst, const char end[0], const char *restrict src) { ssize_t dlen; if (dst == NULL) return NULL; dlen = strscpy(dst, src, end - dst); if (dlen < 0) return NULL; return dst + dlen; }
Quoted 4 lines
This would need to be accompanied by a
seprintf()too, which would be used byusb_make_path()to produce a pointer suitable for chaining. I've been working on adding those.
After sending this patch, I noticed the following comment from an earlier patch:
Quoted 1 line
We don't want to do this as merely an open-coded strlen/sprintf; it doesn't gain us anything.
See:
<https://lore.kernel.org/all/202609151055.AFC6267@keescook/>
Replacing strlcat with an open-coded strlen + snprintf, or with alternatives such as strnlen, strlen, or strscat, would not provide any meaningful benefit.
According to Dmitry's reply to this series, my draft proposal is to replace the usb_make_path() + suffix pattern with a helper defined in the core header, as follows:
static inline __printf(4, 5)
int usb_make_subpath(struct usb_device *dev, char *buf, size_t size,
const char *fmt, ...)
{
struct va_format vaf;
va_list args;
int actual;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
actual = snprintf(buf, size, "usb-%s-%s/%pV", dev->bus->bus_name,
dev->devpath, &vaf);
va_end(args);
return actual >= size ? -1 : actual;
}Quoted 3 lines
If you want to keep it easy, I'd do
strscat(). We can modify it later to be more efficient. After all, we already have the inefficiency of calling strlcat(3) now.
Great. Improving its efficiency is exactly what I would like to do as well
Thanks for reviewing this and for your suggestions.
Shihuang
PATCH 3/5 Input: mouse - replace strlcat() with strscpy()
In reply to Shihuang LiuThe appletouch, bcm5974 and synaptics_usb drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API[1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
--- drivers/input/mouse/appletouch.c | 4 +++- drivers/input/mouse/bcm5974.c | 4 +++- drivers/input/mouse/synaptics_usb.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)
drivers/input/mouse/appletouch.c +3 -1
@@ -832,6 +832,7 @@ static int atp_probe(struct usb_interface *iface,struct usb_endpoint_descriptor *ep;int error;const struct atp_info *info = (const struct atp_info *)id->driver_info; +size_t len;/* set up the endpoint information */ /* use only the first interrupt-in endpoint */
@@ -875,7 +876,8 @@ static int atp_probe(struct usb_interface *iface, goto err_free_buffer;usb_make_path (udev, dev->phys,sizeof (dev->phys)); -strlcat (dev->phys,"/input0" ,sizeof (dev->phys)); + len =strnlen (dev->phys,sizeof (dev->phys)); +strscpy (dev->phys + len,"/input0" ,sizeof (dev->phys) - len); input_dev->name ="appletouch" ; input_dev->phys = dev->phys;
drivers/input/mouse/bcm5974.c +3 -1
@@ -928,6 +928,7 @@ static int bcm5974_probe(struct usb_interface *iface,struct bcm5974 *dev;struct input_dev *input_dev;int error = -ENOMEM ; +size_t len;/* find the product index */ cfg =bcm5974_get_config (udev);
@@ -990,7 +991,8 @@ static int bcm5974_probe(struct usb_interface *iface,/* create bcm5974 device */ usb_make_path (udev, dev->phys,sizeof (dev->phys)); -strlcat (dev->phys,"/input0" ,sizeof (dev->phys)); + len =strnlen (dev->phys,sizeof (dev->phys)); +strscpy (dev->phys + len,"/input0" ,sizeof (dev->phys) - len); input_dev->name ="bcm5974" ; input_dev->phys = dev->phys;
drivers/input/mouse/synaptics_usb.c +3 -1
@@ -279,6 +279,7 @@ static int synusb_probe(struct usb_interface *intf,unsigned int intf_num = intf->cur_altsetting->desc.bInterfaceNumber;unsigned int altsetting =min (intf->num_altsetting,1U );int error; +size_t len; error =usb_set_interface (udev, intf_num, altsetting);if (error) {
@@ -354,7 +355,8 @@ static int synusb_probe(struct usb_interface *intf,strlcat (synusb->name," (Stick)" ,sizeof (synusb->name));usb_make_path (udev, synusb->phys,sizeof (synusb->phys)); -strlcat (synusb->phys,"/input0" ,sizeof (synusb->phys)); + len =strnlen (synusb->phys,sizeof (synusb->phys)); +strscpy (synusb->phys + len,"/input0" ,sizeof (synusb->phys) - len); input_dev->name = synusb->name; input_dev->phys = synusb->phys;
Signature · 1 line
2.43.0
PATCH 4/5 Input: tablet - replace strlcat() with strscpy()
In reply to Shihuang LiuThe acecad, aiptek, hanwang, kbtab and pegasus_notetaker drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API[1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
--- drivers/input/tablet/acecad.c | 4 +++- drivers/input/tablet/aiptek.c | 7 +++++-- drivers/input/tablet/hanwang.c | 4 +++- drivers/input/tablet/kbtab.c | 4 +++- drivers/input/tablet/pegasus_notetaker.c | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-)
drivers/input/tablet/acecad.c +3 -1
@@ -117,6 +117,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_struct input_dev *input_dev;int pipe, maxp;int err; +size_t len;if (interface->desc.bNumEndpoints !=1 )return -ENODEV ;
@@ -161,7 +162,8 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ }usb_make_path (dev, acecad->phys,sizeof (acecad->phys)); -strlcat (acecad->phys,"/input0" ,sizeof (acecad->phys)); + len =strnlen (acecad->phys,sizeof (acecad->phys)); +strscpy (acecad->phys + len,"/input0" ,sizeof (acecad->phys) - len); input_dev->name = acecad->name; input_dev->phys = acecad->phys;
drivers/input/tablet/aiptek.c +5 -2
@@ -1637,6 +1637,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) AIPTEK_PROGRAMMABLE_DELAY_300 };int err = -ENOMEM ; +size_t len;/* programmableDelay is where the command-line specified * delay is kept. We make it the first element of speeds[],
@@ -1707,8 +1708,10 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)*/ usb_make_path (usbdev, aiptek->features.usbPath,sizeof (aiptek->features.usbPath)); -strlcat (aiptek->features.usbPath,"/input0" , -sizeof (aiptek->features.usbPath)); + len =strnlen (aiptek->features.usbPath, +sizeof (aiptek->features.usbPath)); +strscpy (aiptek->features.usbPath + len,"/input0" , +sizeof (aiptek->features.usbPath) - len);/* Set up client data, pointers to open and close routines * for the input device.
drivers/input/tablet/hanwang.c +3 -1
@@ -318,6 +318,7 @@ static int hanwang_probe(struct usb_interface *intf, const struct usb_device_idstruct input_dev *input_dev;int error;int i; +size_t len;if (intf->cur_altsetting->desc.bNumEndpoints <1 )return -ENODEV ;
@@ -351,7 +352,8 @@ static int hanwang_probe(struct usb_interface *intf, const struct usb_device_id hanwang->dev = input_dev;usb_make_path (dev, hanwang->phys,sizeof (hanwang->phys)); -strlcat (hanwang->phys,"/input0" ,sizeof (hanwang->phys)); + len =strnlen (hanwang->phys,sizeof (hanwang->phys)); +strscpy (hanwang->phys + len,"/input0" ,sizeof (hanwang->phys) - len);strscpy (hanwang->name, hanwang->features->name,sizeof (hanwang->name)); input_dev->name = hanwang->name;
drivers/input/tablet/kbtab.c +3 -1
@@ -113,6 +113,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *istruct kbtab *kbtab;struct input_dev *input_dev;int error = -ENOMEM ; +size_t len;if (intf->cur_altsetting->desc.bNumEndpoints <1 )return -ENODEV ;
@@ -138,7 +139,8 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i kbtab->dev = input_dev;usb_make_path (dev, kbtab->phys,sizeof (kbtab->phys)); -strlcat (kbtab->phys,"/input0" ,sizeof (kbtab->phys)); + len =strnlen (kbtab->phys,sizeof (kbtab->phys)); +strscpy (kbtab->phys + len,"/input0" ,sizeof (kbtab->phys) - len); input_dev->name ="KB Gear Tablet" ; input_dev->phys = kbtab->phys;
drivers/input/tablet/pegasus_notetaker.c +3 -1
@@ -277,6 +277,7 @@ static int pegasus_probe(struct usb_interface *intf,struct input_dev *input_dev;int error;int pipe; +size_t len;/* We control interface 0 */ if (intf->cur_altsetting->desc.bInterfaceNumber >=1 )
@@ -355,7 +356,8 @@ static int pegasus_probe(struct usb_interface *intf, le16_to_cpu(dev->descriptor.idProduct));usb_make_path (dev, pegasus->phys,sizeof (pegasus->phys)); -strlcat (pegasus->phys,"/input0" ,sizeof (pegasus->phys)); + len =strnlen (pegasus->phys,sizeof (pegasus->phys)); +strscpy (pegasus->phys + len,"/input0" ,sizeof (pegasus->phys) - len);INIT_WORK (&pegasus->init, pegasus_init);
Signature · 1 line
2.43.0
Re: [PATCH 4/5] Input: tablet - replace strlcat() with strscpy()
Quoted 32 lines · On Sat, 17 Oct 2026 01:04:10 +0800 Shihuang Liu <[email protected]> wrote:
The acecad, aiptek, hanwang, kbtab and
pegasus_notetakerdrivers build the physical path by appending a constant "/input0" suffix withstrlcat()afterusb_make_path().In preparation for removing the deprecated
strlcat()API[1], replace it withstrnlen()followed bystrscpy()into the remainder of the buffer, as commit34b228b739f5("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.Signed-off-by Shihuang Liu <[email protected]>--- drivers/input/tablet/acecad.c | 4 +++- drivers/input/tablet/aiptek.c | 7 +++++-- drivers/input/tablet/hanwang.c | 4 +++- drivers/input/tablet/kbtab.c | 4 +++- drivers/input/tablet/pegasus_notetaker.c | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-)drivers/input/tablet/acecad.c +1
-0@@ -117,6 +117,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_struct input_dev *input_dev;int pipe, maxp;int err; +size_t len;if (interface->desc.bNumEndpoints !=1 )return -ENODEV ;
drivers/input/tablet/acecad.c static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ · line 166
Quoted 6 lines
drivers/input/tablet/acecad.c +2
-1@@ -161,7 +162,8 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ }usb_make_path (dev, acecad->phys,sizeof (acecad->phys)); -strlcat (acecad->phys,"/input0" ,sizeof (acecad->phys)); + len =strnlen (acecad->phys,sizeof (acecad->phys)); +strscpy (acecad->phys + len,"/input0" ,sizeof (acecad->phys) - len);
There is no point replacing strcat() with strlen() + strcpy() (any variants of the functions).
David
Quoted 94 lines
drivers/input/tablet/acecad.c +0
-0input_dev->name = acecad->name; input_dev->phys = acecad->phys;drivers/input/tablet/aiptek.c +5
-2@@ -1637,6 +1637,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) AIPTEK_PROGRAMMABLE_DELAY_300 };int err = -ENOMEM ; +size_t len;/* programmableDelay is where the command-line specified * delay is kept. We make it the first element of speeds[], @@ -1707,8 +1708,10 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)*/ usb_make_path (usbdev, aiptek->features.usbPath,sizeof (aiptek->features.usbPath)); -strlcat (aiptek->features.usbPath,"/input0" , -sizeof (aiptek->features.usbPath)); + len =strnlen (aiptek->features.usbPath, +sizeof (aiptek->features.usbPath)); +strscpy (aiptek->features.usbPath + len,"/input0" , +sizeof (aiptek->features.usbPath) - len);/* Set up client data, pointers to open and close routines * for the input device. drivers/input/tablet/hanwang.c +3
-1@@ -318,6 +318,7 @@ static int hanwang_probe(struct usb_interface *intf, const struct usb_device_idstruct input_dev *input_dev;int error;int i; +size_t len;if (intf->cur_altsetting->desc.bNumEndpoints <1 )return -ENODEV ;@@ -351,7 +352,8 @@ static int hanwang_probe(struct usb_interface *intf, const struct usb_device_id hanwang->dev = input_dev;usb_make_path (dev, hanwang->phys,sizeof (hanwang->phys)); -strlcat (hanwang->phys,"/input0" ,sizeof (hanwang->phys)); + len =strnlen (hanwang->phys,sizeof (hanwang->phys)); +strscpy (hanwang->phys + len,"/input0" ,sizeof (hanwang->phys) - len);strscpy (hanwang->name, hanwang->features->name,sizeof (hanwang->name)); input_dev->name = hanwang->name;drivers/input/tablet/kbtab.c +3
-1@@ -113,6 +113,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *istruct kbtab *kbtab;struct input_dev *input_dev;int error = -ENOMEM ; +size_t len;if (intf->cur_altsetting->desc.bNumEndpoints <1 )return -ENODEV ;@@ -138,7 +139,8 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i kbtab->dev = input_dev;usb_make_path (dev, kbtab->phys,sizeof (kbtab->phys)); -strlcat (kbtab->phys,"/input0" ,sizeof (kbtab->phys)); + len =strnlen (kbtab->phys,sizeof (kbtab->phys)); +strscpy (kbtab->phys + len,"/input0" ,sizeof (kbtab->phys) - len); input_dev->name ="KB Gear Tablet" ; input_dev->phys = kbtab->phys;drivers/input/tablet/pegasus_notetaker.c +3
-1@@ -277,6 +277,7 @@ static int pegasus_probe(struct usb_interface *intf,struct input_dev *input_dev;int error;int pipe; +size_t len;/* We control interface 0 */ if (intf->cur_altsetting->desc.bInterfaceNumber >=1 )@@ -355,7 +356,8 @@ static int pegasus_probe(struct usb_interface *intf, le16_to_cpu(dev->descriptor.idProduct));usb_make_path (dev, pegasus->phys,sizeof (pegasus->phys)); -strlcat (pegasus->phys,"/input0" ,sizeof (pegasus->phys)); + len =strnlen (pegasus->phys,sizeof (pegasus->phys)); +strscpy (pegasus->phys + len,"/input0" ,sizeof (pegasus->phys) - len);INIT_WORK (&pegasus->init, pegasus_init);
PATCH 5/5 Input: touchscreen - replace strlcat() with strscpy()
In reply to Shihuang LiuThe sur40 and usbtouchscreen drivers build the physical path by appending a constant "/input0" suffix with strlcat() after usb_make_path().
In preparation for removing the deprecated strlcat() API[1], replace it with strnlen() followed by strscpy() into the remainder of the buffer, as commit 34b228b739f5 ("HID: usbhid: replace strlcat with better alternatives") did for the usbhid drivers.
--- drivers/input/touchscreen/sur40.c | 4 +++- drivers/input/touchscreen/usbtouchscreen.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/input/touchscreen/sur40.c +3 -1
@@ -657,6 +657,7 @@ static int sur40_probe(struct usb_interface *interface,struct usb_endpoint_descriptor *endpoint;struct input_dev *input;int error; +size_t len;/* Check if we really have the right interface. */ iface_desc = interface->cur_altsetting;
@@ -691,7 +692,8 @@ static int sur40_probe(struct usb_interface *interface, input->name =DRIVER_LONG ;usb_to_input_id (usbdev, &input->id);usb_make_path (usbdev, sur40->phys,sizeof (sur40->phys)); -strlcat (sur40->phys,"/input0" ,sizeof (sur40->phys)); + len =strnlen (sur40->phys,sizeof (sur40->phys)); +strscpy (sur40->phys + len,"/input0" ,sizeof (sur40->phys) - len); input->phys = sur40->phys; input->dev.parent = &interface->dev;
drivers/input/touchscreen/usbtouchscreen.c +3 -1
@@ -1438,6 +1438,7 @@ static int usbtouch_probe(struct usb_interface *intf,struct usb_device *udev =interface_to_usbdev (intf);const struct usbtouch_device_info *type;int err; +size_t len;/* some devices are ignored */ type = (const struct usbtouch_device_info *)id->driver_info;
@@ -1513,7 +1514,8 @@ static int usbtouch_probe(struct usb_interface *intf, le16_to_cpu(udev->descriptor.idProduct));usb_make_path (udev, usbtouch->phys,sizeof (usbtouch->phys)); -strlcat (usbtouch->phys,"/input0" ,sizeof (usbtouch->phys)); + len =strnlen (usbtouch->phys,sizeof (usbtouch->phys)); +strscpy (usbtouch->phys + len,"/input0" ,sizeof (usbtouch->phys) - len); input_dev->name = usbtouch->name; input_dev->phys = usbtouch->phys;
Signature · 1 line
2.43.0