Commit 2451a848 authored by Silviu-Mihai Popescu's avatar Silviu-Mihai Popescu Committed by Greg Kroah-Hartman

parport: use kmemdup instead of kmalloc + memcpy

This replaces calls to kmalloc followed by memcpy with a single call to
kmemdup. This was found via make coccicheck.
Signed-off-by: default avatarSilviu-Mihai Popescu <silviupopescu1990@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5bcdf0ce
...@@ -246,14 +246,14 @@ struct parport *parport_gsc_probe_port(unsigned long base, ...@@ -246,14 +246,14 @@ struct parport *parport_gsc_probe_port(unsigned long base,
printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base); printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
return NULL; return NULL;
} }
ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL); ops = kmemdup(&parport_gsc_ops, sizeof(struct parport_operations),
GFP_KERNEL);
if (!ops) { if (!ops) {
printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n", printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
base); base);
kfree (priv); kfree (priv);
return NULL; return NULL;
} }
memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
priv->ctr = 0xc; priv->ctr = 0xc;
priv->ctr_writable = 0xff; priv->ctr_writable = 0xff;
priv->dma_buf = 0; priv->dma_buf = 0;
......
...@@ -284,12 +284,11 @@ static int bpp_probe(struct platform_device *op) ...@@ -284,12 +284,11 @@ static int bpp_probe(struct platform_device *op)
size = resource_size(&op->resource[0]); size = resource_size(&op->resource[0]);
dma = PARPORT_DMA_NONE; 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) if (!ops)
goto out_unmap; goto out_unmap;
memcpy (ops, &parport_sunbpp_ops, sizeof(struct parport_operations));
dprintk(("register_port\n")); dprintk(("register_port\n"));
if (!(p = parport_register_port((unsigned long)base, irq, dma, ops))) if (!(p = parport_register_port((unsigned long)base, irq, dma, ops)))
goto out_free_ops; goto out_free_ops;
......
...@@ -476,10 +476,9 @@ int parport_proc_register(struct parport *port) ...@@ -476,10 +476,9 @@ int parport_proc_register(struct parport *port)
struct parport_sysctl_table *t; struct parport_sysctl_table *t;
int i; int i;
t = kmalloc(sizeof(*t), GFP_KERNEL); t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
if (t == NULL) if (t == NULL)
return -ENOMEM; return -ENOMEM;
memcpy(t, &parport_sysctl_template, sizeof(*t));
t->device_dir[0].extra1 = port; t->device_dir[0].extra1 = port;
...@@ -523,10 +522,9 @@ int parport_device_proc_register(struct pardevice *device) ...@@ -523,10 +522,9 @@ int parport_device_proc_register(struct pardevice *device)
struct parport_device_sysctl_table *t; struct parport_device_sysctl_table *t;
struct parport * port = device->port; struct parport * port = device->port;
t = kmalloc(sizeof(*t), GFP_KERNEL); t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
if (t == NULL) if (t == NULL)
return -ENOMEM; return -ENOMEM;
memcpy(t, &parport_device_sysctl_template, sizeof(*t));
t->dev_dir[0].child = t->parport_dir; t->dev_dir[0].child = t->parport_dir;
t->parport_dir[0].child = t->port_dir; t->parport_dir[0].child = t->port_dir;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment