From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: linux-input@vger.kernel.org, linux-hardening@vger.kernel.org,
Marcus Folkesson <marcus.folkesson@gmail.com>,
Dmitry Torokhov <dmitry.torokhov@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 v2 1/6] USB: add usb_make_subpath() for formatted device subpaths
Date: Thu, 22 Oct 2026 11:59:16 +0200 [thread overview]
Message-ID: <atneGH0t_T-75WmE@debian> (raw)
In-Reply-To: <tlemhufl7x3zatbf7ygcfnshinyz4bunroyhegmyxutgooqbcc@wtpqkldesosb>
[-- Attachment #1: Type: text/plain, Size: 3395 bytes --]
Hi Shihuang,
> Date: 2026-10-22 15:08:58+0800
> From: Shihuang Liu <shlomojune6@gmail.com>
>
> On Wed, Oct 21, 2026 at 03:17:56PM +0200, Alejandro Colomar wrote:
> > Hi Shihuang,
> >
> > > Date: 2026-10-21 20:31:41+0800
> > > From: Shihuang Liu <shlomojune6@gmail.com>
> > >
> > > USB drivers often build device paths by calling usb_make_path() :and
> > > then appending a subpath. Several callers use the deprecated strlcat()
> > > API for this.
> > >
> > > In preparation for removing the deprecated strlcat() API[1], add
> > > usb_make_subpath() to format the USB device path.
> > >
> > > Link: https://github.com/KSPP/linux/issues/370 [1]
> > > Signed-off-by: Shihuang Liu <shlomojune6@gmail.com>
> > > ---
> > > include/linux/usb.h | 29 +++++++++++++++++++++++++++++
> > > 1 file changed, 29 insertions(+)
> > >
> > > diff --git a/include/linux/usb.h b/include/linux/usb.h
> > > index 1da4ad1610bca..c90ccea0cdbf6 100644
> > > --- a/include/linux/usb.h
> > > +++ b/include/linux/usb.h
> > > @@ -14,6 +14,7 @@
> > > #include <linux/errno.h> /* for -ENODEV */
> > > #include <linux/delay.h> /* for mdelay() */
> > > #include <linux/interrupt.h> /* for in_interrupt() */
> > > +#include <linux/stdarg.h> /* for va_list */
> > > #include <linux/list.h> /* for struct list_head */
> > > #include <linux/kref.h> /* for struct kref */
> > > #include <linux/device.h> /* for struct device */
> > > @@ -987,6 +988,34 @@ static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size)
> > > return (actual >= (int)size) ? -1 : actual;
> > > }
> > >
> > > +/**
> > > + * usb_make_subpath - returns a stable device path and formatted subpath
> > > + * @dev: the device whose path is being constructed
> > > + * @buf: where to put the string
> > > + * @size: how big is "buf"?
> > > + * @fmt: format string for the subpath, without the leading slash
> > > + * @...: arguments for @fmt
> > > + *
> > > + * Return: Length of the string (> 0) or negative if size was too small.
> > > + */
> > > +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 >= (int)size) ? -1 : actual;
> >
> > Why are you open-coding usb_make_path() here instead of calling it?
> >
> >
> > Have a lovely day!
> > Alex
> >
> Hi, Alex
>
> With open-coding, a single snprintf() is enough, so we don't need to
> call usb_make_path() and then another function to append the suffix.
The number of function calls should be negligible compared to all the
work done by this function. The readability and robustness is way more
important.
Have a lovely day!
Alex
>
> Thanks,
> Shihuang
> > > +}
> > > +
> > > /*-------------------------------------------------------------------------*/
> > >
> > > #define USB_DEVICE_ID_MATCH_DEVICE \
> > > --
> > > 2.43.0
> > >
> > >
> >
> > --
> > <https://www.alejandro-colomar.es>
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-10-22 9:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 12:31 [PATCH v2 0/6] USB: add usb_make_subpath() to replace strlcat() in input drivers Shihuang Liu
2026-10-21 12:31 ` [PATCH v2 1/6] USB: add usb_make_subpath() for formatted device subpaths Shihuang Liu
2026-10-21 13:17 ` Alejandro Colomar
2026-10-22 7:08 ` Shihuang Liu
2026-10-22 9:59 ` Alejandro Colomar [this message]
2026-10-21 15:20 ` Greg KH
2026-10-22 6:49 ` Shihuang Liu
2026-10-21 12:31 ` [PATCH v2 2/6] Input: joystick - use usb_make_subpath() Shihuang Liu
2026-10-21 13:21 ` Alejandro Colomar
2026-10-21 17:00 ` Dmitry Torokhov
2026-10-21 17:20 ` Alejandro Colomar
2026-10-22 7:36 ` Shihuang Liu
2026-10-22 10:03 ` Alejandro Colomar
2026-10-21 12:31 ` [PATCH v2 3/6] Input: misc " Shihuang Liu
2026-10-21 12:31 ` [PATCH v2 4/6] Input: mouse " Shihuang Liu
2026-10-21 12:31 ` [PATCH v2 5/6] Input: tablet " Shihuang Liu
2026-10-21 12:31 ` [PATCH v2 6/6] Input: touchscreen " Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 0/6] USB: add usb_make_subpath() to replace strlcat() in input drivers Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 1/6] USB: add usb_make_subpath() for formatted device subpaths Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 2/6] Input: joystick - use usb_make_subpath() Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 3/6] Input: misc " Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 4/6] Input: mouse " Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 5/6] Input: tablet " Shihuang Liu
2026-10-22 7:09 ` [PATCH v2 RESEND 6/6] 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=atneGH0t_T-75WmE@debian \
--to=alx+linux-hardening@kernel.org \
--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=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
all inboxes | Powered by JetHome®