platform/x86: wmi: Replace kmalloc + sprintf() with kasprintf()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 16 Feb 2018 15:40:24 +0000 (17:40 +0200)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 19 Feb 2018 15:03:43 +0000 (17:03 +0200)
kasprintf() does the job of two: kmalloc() and sprintf().
Replace two calls with one.

Reviewed-by: Darren Hart (VMware) <dvhart@infradead.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/wmi.c

index c0c8945603cbbdd6284ff60b5df4d118502305d5..4e76ffcb5394defbe1e1ff1db61dd7604363019d 100644 (file)
@@ -933,12 +933,11 @@ static int wmi_dev_probe(struct device *dev)
                        goto probe_failure;
                }
 
-               buf = kmalloc(strlen(wdriver->driver.name) + 5, GFP_KERNEL);
+               buf = kasprintf(GFP_KERNEL, "wmi/%s", wdriver->driver.name);
                if (!buf) {
                        ret = -ENOMEM;
                        goto probe_string_failure;
                }
-               sprintf(buf, "wmi/%s", wdriver->driver.name);
                wblock->char_dev.minor = MISC_DYNAMIC_MINOR;
                wblock->char_dev.name = buf;
                wblock->char_dev.fops = &wmi_fops;