driver core: module.c: Use kasprintf
authorJulia Lawall <julia@diku.dk>
Wed, 10 Mar 2010 21:18:13 +0000 (22:18 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 21 May 2010 16:37:29 +0000 (09:37 -0700)
kasprintf combines kmalloc and sprintf, and takes care of the size
calculation itself.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

  a =
-  \(kmalloc\|kzalloc\)(...,flag)
+  kasprintf(flag,args)
  <... when != a
  if (a == NULL || ...) S
  ...>
- sprintf(a,args);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/module.c

index f32f2f9b7be5fadb9a6f16300dc91cfcd7065ea3..db930d3ee31259f6a17b9dd33eb16caee4e12f5c 100644 (file)
@@ -15,12 +15,10 @@ static char *make_driver_name(struct device_driver *drv)
 {
        char *driver_name;
 
-       driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
-                             GFP_KERNEL);
+       driver_name = kasprintf(GFP_KERNEL, "%s:%s", drv->bus->name, drv->name);
        if (!driver_name)
                return NULL;
 
-       sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
        return driver_name;
 }