drivers/char/ppdev.c: use kasprintf
authorJulia Lawall <julia@diku.dk>
Wed, 26 May 2010 21:43:55 +0000 (14:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 27 May 2010 16:12:50 +0000 (09:12 -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>
Cc: Michael Buesch <mb@bu3sch.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/char/ppdev.c

index fdd3754..02abfdd 100644 (file)
@@ -287,12 +287,10 @@ static int register_device (int minor, struct pp_struct *pp)
        char *name;
        int fl;
 
        char *name;
        int fl;
 
-       name = kmalloc (strlen (CHRDEV) + 3, GFP_KERNEL);
+       name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
        if (name == NULL)
                return -ENOMEM;
 
        if (name == NULL)
                return -ENOMEM;
 
-       sprintf (name, CHRDEV "%x", minor);
-
        port = parport_find_number (minor);
        if (!port) {
                printk (KERN_WARNING "%s: no associated port!\n", name);
        port = parport_find_number (minor);
        if (!port) {
                printk (KERN_WARNING "%s: no associated port!\n", name);