Skip to contentSkip to conversation

USB: chaoskey: Use kasprintf() over strcpy()/strcat()

PATCH In review Kees Cook 2 participants 2 messages Feb 17, 2018

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 USB: chaoskey: Use kasprintf() over strcpy()/strcat()

Instead of kmalloc() with manually calculated values followed by multiple strcpy()/strcat() calls, just fold it all into a single kasprintf() call.

---
 drivers/usb/misc/chaoskey.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/misc/chaoskey.c +2 -6
index 716cb515523e..cf5828ce927a 100644
@@ -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;