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

staging: comedi: use memdup_user to simplify code

Use memdup_user rather than duplicating implementation. Fix following
coccinelle warnings:

drivers/staging/comedi/comedi_fops.c:1425:5-12: WARNING opportunity for memdup_user
drivers/staging/comedi/comedi_fops.c:1553:6-13: WARNING opportunity for memdup_user

Signed-off-by: Teodora Baluta <teobaluta@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Teodora Baluta and committed by
Greg Kroah-Hartman
f0c80e4e 8cf9ff57

+10 -23
+10 -23
drivers/staging/comedi/comedi_fops.c
··· 1421 1421 async->cmd = cmd; 1422 1422 async->cmd.data = NULL; 1423 1423 /* load channel/gain list */ 1424 - async->cmd.chanlist = 1425 - kmalloc(async->cmd.chanlist_len * sizeof(int), GFP_KERNEL); 1426 - if (!async->cmd.chanlist) { 1427 - DPRINTK("allocation failed\n"); 1428 - return -ENOMEM; 1429 - } 1430 - 1431 - if (copy_from_user(async->cmd.chanlist, user_chanlist, 1432 - async->cmd.chanlist_len * sizeof(int))) { 1433 - DPRINTK("fault reading chanlist\n"); 1434 - ret = -EFAULT; 1424 + async->cmd.chanlist = memdup_user(user_chanlist, 1425 + async->cmd.chanlist_len * sizeof(int)); 1426 + if (IS_ERR(async->cmd.chanlist)) { 1427 + ret = PTR_ERR(async->cmd.chanlist); 1428 + DPRINTK("memdup_user failed with code %d\n", ret); 1435 1429 goto cleanup; 1436 1430 } 1437 1431 ··· 1543 1549 1544 1550 /* load channel/gain list */ 1545 1551 if (cmd.chanlist) { 1546 - chanlist = 1547 - kmalloc(cmd.chanlist_len * sizeof(int), GFP_KERNEL); 1548 - if (!chanlist) { 1549 - DPRINTK("allocation failed\n"); 1550 - ret = -ENOMEM; 1551 - goto cleanup; 1552 - } 1553 - 1554 - if (copy_from_user(chanlist, user_chanlist, 1555 - cmd.chanlist_len * sizeof(int))) { 1556 - DPRINTK("fault reading chanlist\n"); 1557 - ret = -EFAULT; 1552 + chanlist = memdup_user(user_chanlist, 1553 + cmd.chanlist_len * sizeof(int)); 1554 + if (IS_ERR(chanlist)) { 1555 + ret = PTR_ERR(chanlist); 1556 + DPRINTK("memdup_user exited with code %d", ret); 1558 1557 goto cleanup; 1559 1558 } 1560 1559