From: Greg KH <greg@kroah.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Shihuang Liu <shlomojune6@gmail.com>,
linux-input@vger.kernel.org, linux-hardening@vger.kernel.org,
Marcus Folkesson <marcus.folkesson@gmail.com>,
Ville Syrjala <syrjala@sci.fi>,
Henk Vergonet <Henk.Vergonet@gmail.com>,
Henrik Rydberg <rydberg@bitmath.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] Input: joystick - replace strlcat() with strscpy()
Date: Sat, 17 Oct 2026 10:19:59 +0200 [thread overview]
Message-ID: <2026101727-ebay-five-72f8@gregkh> (raw)
In-Reply-To: <30bc6e07072076b0591fd416f50f4fc3@gmail.com>
On Fri, Oct 16, 2026 at 12:17:05PM -0700, Dmitry Torokhov wrote:
> Hi Shihuang,
>
> On Sat, Oct 17, 2026 at 01:04:07AM +0800, Shihuang Liu wrote:
> > 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.
> ...
> > 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);
>
> 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.
I'm all for that too, and putting it in the USB core for everyone to use
would be great.
thanks,
greg k-h
next prev parent reply other threads:[~2026-10-17 8:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 17:04 [PATCH 0/5] Input: replace strlcat() with strscpy() in USB input drivers Shihuang Liu
2026-10-16 17:04 ` [PATCH 1/5] Input: joystick - replace strlcat() with strscpy() Shihuang Liu
2026-10-16 19:17 ` Dmitry Torokhov
2026-10-17 8:19 ` Greg KH [this message]
2026-10-16 17:04 ` [PATCH 2/5] Input: misc " Shihuang Liu
2026-10-16 17:04 ` [PATCH 3/5] Input: mouse " Shihuang Liu
2026-10-16 17:04 ` [PATCH 4/5] Input: tablet " Shihuang Liu
2026-10-17 22:11 ` David Laight
2026-10-16 17:04 ` [PATCH 5/5] Input: touchscreen " Shihuang Liu
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=2026101727-ebay-five-72f8@gregkh \
--to=greg@kroah.com \
--cc=Henk.Vergonet@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.folkesson@gmail.com \
--cc=rydberg@bitmath.org \
--cc=shlomojune6@gmail.com \
--cc=syrjala@sci.fi \
/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