parport: use kmemdup instead of kmalloc + memcpy
authorSilviu-Mihai Popescu <silviupopescu1990@gmail.com>
Mon, 11 Mar 2013 16:39:22 +0000 (18:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 17:42:06 +0000 (10:42 -0700)
This replaces calls to kmalloc followed by memcpy with a single call to
kmemdup. This was found via make coccicheck.

Signed-off-by: Silviu-Mihai Popescu <silviupopescu1990@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/parport/parport_gsc.c
drivers/parport/parport_sunbpp.c
drivers/parport/procfs.c

index 050773c368238d0d6fe7ffdd53db1e3ecc5ebc62..a5251cb5fb0c616f4254c025bbd77d5925014a2f 100644 (file)
@@ -246,14 +246,14 @@ struct parport *parport_gsc_probe_port(unsigned long base,
                printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
                return NULL;
        }
-       ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
+       ops = kmemdup(&parport_gsc_ops, sizeof(struct parport_operations),
+                     GFP_KERNEL);
        if (!ops) {
                printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
                        base);
                kfree (priv);
                return NULL;
        }
-       memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
        priv->ctr = 0xc;
        priv->ctr_writable = 0xff;
        priv->dma_buf = 0;
index 5c4b6a1db6cad94e078d0a60489832b265fc5fea..dffd6d0bd15b7795ec1a1d796b5652e8c540944c 100644 (file)
@@ -284,12 +284,11 @@ static int bpp_probe(struct platform_device *op)
        size = resource_size(&op->resource[0]);
        dma = PARPORT_DMA_NONE;
 
-       ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
+       ops = kmemdup(&parport_sunbpp_ops, sizeof(struct parport_operations),
+                     GFP_KERNEL);
         if (!ops)
                goto out_unmap;
 
-        memcpy (ops, &parport_sunbpp_ops, sizeof(struct parport_operations));
-
        dprintk(("register_port\n"));
        if (!(p = parport_register_port((unsigned long)base, irq, dma, ops)))
                goto out_free_ops;
index 3f56bc086cb51b25eb99a4c7fc169d205d639812..92ed045a5f939b6a780db542a3b93ed2814b7765 100644 (file)
@@ -476,10 +476,9 @@ int parport_proc_register(struct parport *port)
        struct parport_sysctl_table *t;
        int i;
 
-       t = kmalloc(sizeof(*t), GFP_KERNEL);
+       t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
                return -ENOMEM;
-       memcpy(t, &parport_sysctl_template, sizeof(*t));
 
        t->device_dir[0].extra1 = port;
 
@@ -523,10 +522,9 @@ int parport_device_proc_register(struct pardevice *device)
        struct parport_device_sysctl_table *t;
        struct parport * port = device->port;
        
-       t = kmalloc(sizeof(*t), GFP_KERNEL);
+       t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
                return -ENOMEM;
-       memcpy(t, &parport_device_sysctl_template, sizeof(*t));
 
        t->dev_dir[0].child = t->parport_dir;
        t->parport_dir[0].child = t->port_dir;