The sur40 and usbtouchscreen 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/touchscreen/sur40.c          | 4 +++-
 drivers/input/touchscreen/usbtouchscreen.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/sur40.c 
b/drivers/input/touchscreen/sur40.c
index 77ec2c94b91fd..72ec3882e3d40 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -657,6 +657,7 @@ static int sur40_probe(struct usb_interface *interface,
        struct usb_endpoint_descriptor *endpoint;
        struct input_dev *input;
        int error;
+       size_t len;
 
        /* Check if we really have the right interface. */
        iface_desc = interface->cur_altsetting;
@@ -691,7 +692,8 @@ static int sur40_probe(struct usb_interface *interface,
        input->name = DRIVER_LONG;
        usb_to_input_id(usbdev, &input->id);
        usb_make_path(usbdev, sur40->phys, sizeof(sur40->phys));
-       strlcat(sur40->phys, "/input0", sizeof(sur40->phys));
+       len = strnlen(sur40->phys, sizeof(sur40->phys));
+       strscpy(sur40->phys + len, "/input0", sizeof(sur40->phys) - len);
        input->phys = sur40->phys;
        input->dev.parent = &interface->dev;
 
diff --git a/drivers/input/touchscreen/usbtouchscreen.c 
b/drivers/input/touchscreen/usbtouchscreen.c
index 0bbacb517c286..e6f88bd9a3408 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -1438,6 +1438,7 @@ static int usbtouch_probe(struct usb_interface *intf,
        struct usb_device *udev = interface_to_usbdev(intf);
        const struct usbtouch_device_info *type;
        int err;
+       size_t len;
 
        /* some devices are ignored */
        type = (const struct usbtouch_device_info *)id->driver_info;
@@ -1513,7 +1514,8 @@ static int usbtouch_probe(struct usb_interface *intf,
                         le16_to_cpu(udev->descriptor.idProduct));
 
        usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
-       strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
+       len = strnlen(usbtouch->phys, sizeof(usbtouch->phys));
+       strscpy(usbtouch->phys + len, "/input0", sizeof(usbtouch->phys) - len);
 
        input_dev->name = usbtouch->name;
        input_dev->phys = usbtouch->phys;
-- 
2.43.0


Reply via email to