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.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Shihuang Liu <[email protected]>
---
 drivers/input/joystick/pxrc.c | 4 +++-
 drivers/input/joystick/xpad.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/input/joystick/pxrc.c b/drivers/input/joystick/pxrc.c
index 52d9eab667b7a..9abda2394fffb 100644
--- a/drivers/input/joystick/pxrc.c
+++ b/drivers/input/joystick/pxrc.c
@@ -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);
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index feb8f368f834e..4f2bb9ca74936 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -2045,6 +2045,7 @@ static int xpad_probe(struct usb_interface *intf, const 
struct usb_device_id *id
        struct 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 *id
                return -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);
-- 
2.43.0


Reply via email to