Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Silviu-Mihai Popescu <silviupopescu1990@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Silviu-Mihai Popescu and committed by
Greg Kroah-Hartman
2451a848 5bcdf0ce

+6 -9
+2 -2
drivers/parport/parport_gsc.c
··· 246 246 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base); 247 247 return NULL; 248 248 } 249 - ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL); 249 + ops = kmemdup(&parport_gsc_ops, sizeof(struct parport_operations), 250 + GFP_KERNEL); 250 251 if (!ops) { 251 252 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n", 252 253 base); 253 254 kfree (priv); 254 255 return NULL; 255 256 } 256 - memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations)); 257 257 priv->ctr = 0xc; 258 258 priv->ctr_writable = 0xff; 259 259 priv->dma_buf = 0;
+2 -3
drivers/parport/parport_sunbpp.c
··· 284 284 size = resource_size(&op->resource[0]); 285 285 dma = PARPORT_DMA_NONE; 286 286 287 - ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL); 287 + ops = kmemdup(&parport_sunbpp_ops, sizeof(struct parport_operations), 288 + GFP_KERNEL); 288 289 if (!ops) 289 290 goto out_unmap; 290 - 291 - memcpy (ops, &parport_sunbpp_ops, sizeof(struct parport_operations)); 292 291 293 292 dprintk(("register_port\n")); 294 293 if (!(p = parport_register_port((unsigned long)base, irq, dma, ops)))
+2 -4
drivers/parport/procfs.c
··· 476 476 struct parport_sysctl_table *t; 477 477 int i; 478 478 479 - t = kmalloc(sizeof(*t), GFP_KERNEL); 479 + t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); 480 480 if (t == NULL) 481 481 return -ENOMEM; 482 - memcpy(t, &parport_sysctl_template, sizeof(*t)); 483 482 484 483 t->device_dir[0].extra1 = port; 485 484 ··· 522 523 struct parport_device_sysctl_table *t; 523 524 struct parport * port = device->port; 524 525 525 - t = kmalloc(sizeof(*t), GFP_KERNEL); 526 + t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL); 526 527 if (t == NULL) 527 528 return -ENOMEM; 528 - memcpy(t, &parport_device_sysctl_template, sizeof(*t)); 529 529 530 530 t->dev_dir[0].child = t->parport_dir; 531 531 t->parport_dir[0].child = t->port_dir;