Re: [PATCH v2 2/6] Input: joystick - use usb_make_subpath()
From: Shihuang Liu
Date: Thu Oct 22 2026 - 03:36:48 EST
On Wed, Oct 21, 2026 at 03:21:28PM +0200, Alejandro Colomar wrote:
> Hi Shihuang,
>
> > Date: 2026-10-21 20:31:42+0800
> > From: Shihuang Liu <shlomojune6@xxxxxxxxx>
> >
> > The pxrc and xpad drivers build their input device physical paths
> > by appending "/input0" with strlcat() after usb_make_path().
> >
> > In preparation for removing the deprecated strlcat() API [1],
> > replace each pair of calls with usb_make_subpath(). The helper
> > formats the USB path and the "input0" subpath in one call,
> > avoiding a separate buffer scan and append operation.
> >
> > Link: https://github.com/KSPP/linux/issues/370 [1]
> > Signed-off-by: Shihuang Liu <shlomojune6@xxxxxxxxx>
> > ---
> > drivers/input/joystick/pxrc.c | 3 +--
> > drivers/input/joystick/xpad.c | 3 +--
> > 2 files changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/input/joystick/pxrc.c b/drivers/input/joystick/pxrc.c
> > index 52d9eab667b7a..1a11e73d7cd04 100644
> > --- a/drivers/input/joystick/pxrc.c
> > +++ b/drivers/input/joystick/pxrc.c
> > @@ -169,8 +169,7 @@ 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));
> > + usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");
>
> To be honest, I think the composed approach is more readable. You don't
> need to learn a new _subpath function with all the details it has.
>
> Everyone knows what a str*cat() (or str*cpy, FWIW) function does.
>
> I'd rather improve this by adding strscat(). The reason for removing
> strlcat(3) is that it is vulnerable to DoS, and that it is inefficient,
> but it is good at producing readable code, and a replacement should not
> degrade that.
>
>
> Have a lovely day!
> Alex
>
Besides that, strscat() has other issues:
- The `sizeof(buf) - len` arithmetic is a classic source of
off-by-one bugs.
- any future change means re-deriving the offsets all over again.
I'd prefer to avoid strscat() here.
Thanks
Shihuang
> > pxrc->input->phys = pxrc->phys;
> >
> > usb_to_input_id(udev, &pxrc->input->id);
> > diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
> > index feb8f368f834e..0f7ca5adaeee7 100644
> > --- a/drivers/input/joystick/xpad.c
> > +++ b/drivers/input/joystick/xpad.c
> > @@ -2059,8 +2059,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
> > if (!xpad)
> > return -ENOMEM;
> >
> > - usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
> > - strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
> > + usb_make_subpath(udev, xpad->phys, sizeof(xpad->phys), "input0");
> >
> > xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN,
> > GFP_KERNEL, &xpad->idata_dma);
> > --
> > 2.43.0
> >
> >
>
> --
> <https://www.alejandro-colomar.es>