The 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.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Shihuang Liu <[email protected]>
---
 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(-)

diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index eebeb57515e1c..aa43f7ae274ce 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -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;
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index e772bac3b64c0..64e26cca2c2c4 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -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;
diff --git a/drivers/input/mouse/synaptics_usb.c 
b/drivers/input/mouse/synaptics_usb.c
index 880a0c79148cd..e1a4a9746dbee 100644
--- a/drivers/input/mouse/synaptics_usb.c
+++ b/drivers/input/mouse/synaptics_usb.c
@@ -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;
-- 
2.43.0


Reply via email to