USB: chaoskey: Use kasprintf() over strcpy()/strcat()
authorKees Cook <keescook@chromium.org>
Sat, 17 Feb 2018 04:55:30 +0000 (20:55 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Feb 2018 14:17:05 +0000 (15:17 +0100)
Instead of kmalloc() with manually calculated values followed by
multiple strcpy()/strcat() calls, just fold it all into a single
kasprintf() call.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/chaoskey.c

index 716cb515523e3cc0e8ee280b8d24ac2258256d8d..cf5828ce927a835af30de0dd739d0ce7e455a2db 100644 (file)
@@ -168,14 +168,10 @@ static int chaoskey_probe(struct usb_interface *interface,
         */
 
        if (udev->product && udev->serial) {
-               dev->name = kmalloc(strlen(udev->product) + 1 +
-                                   strlen(udev->serial) + 1, GFP_KERNEL);
+               dev->name = kasprintf(GFP_KERNEL, "%s-%s", udev->product,
+                                     udev->serial);
                if (dev->name == NULL)
                        goto out;
-
-               strcpy(dev->name, udev->product);
-               strcat(dev->name, "-");
-               strcat(dev->name, udev->serial);
        }
 
        dev->interface = interface;