Staging: vme: devices: Use kasprintf
authorVaishali Thakkar <vthakkar1994@gmail.com>
Thu, 23 Oct 2014 07:57:46 +0000 (13:27 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Oct 2014 02:33:05 +0000 (10:33 +0800)
This patch uses kasprintf which combines kmalloc and sprintf.
kasprintf also takes care of the size calculation.

This is done using Coccinelle. Semantic patch used is as follows:

@@
expression a,flag;
expression list args;
statement S;
@@

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

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vme/devices/vme_pio2_gpio.c

index c64776f71809f0fc9ee04232a9cef72647897989..da34d5529f5154d35f259ec81eca147e868cf3e1 100644 (file)
@@ -191,11 +191,11 @@ int pio2_gpio_init(struct pio2_card *card)
        int retval = 0;
        char *label;
 
-       label = kmalloc(PIO2_NUM_CHANNELS, GFP_KERNEL);
+       label = kasprintf(GFP_KERNEL,
+                         "%s@%s", driver_name, dev_name(&card->vdev->dev));
        if (label == NULL)
                return -ENOMEM;
 
-       sprintf(label, "%s@%s", driver_name, dev_name(&card->vdev->dev));
        card->gc.label = label;
 
        card->gc.ngpio = PIO2_NUM_CHANNELS;