Commit f0c80e4e authored by Teodora Baluta's avatar Teodora Baluta Committed by Greg Kroah-Hartman

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: default avatarTeodora Baluta <teobaluta@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8cf9ff57
...@@ -1421,17 +1421,11 @@ static int do_cmd_ioctl(struct comedi_device *dev, ...@@ -1421,17 +1421,11 @@ static int do_cmd_ioctl(struct comedi_device *dev,
async->cmd = cmd; async->cmd = cmd;
async->cmd.data = NULL; async->cmd.data = NULL;
/* load channel/gain list */ /* load channel/gain list */
async->cmd.chanlist = async->cmd.chanlist = memdup_user(user_chanlist,
kmalloc(async->cmd.chanlist_len * sizeof(int), GFP_KERNEL); async->cmd.chanlist_len * sizeof(int));
if (!async->cmd.chanlist) { if (IS_ERR(async->cmd.chanlist)) {
DPRINTK("allocation failed\n"); ret = PTR_ERR(async->cmd.chanlist);
return -ENOMEM; DPRINTK("memdup_user failed with code %d\n", ret);
}
if (copy_from_user(async->cmd.chanlist, user_chanlist,
async->cmd.chanlist_len * sizeof(int))) {
DPRINTK("fault reading chanlist\n");
ret = -EFAULT;
goto cleanup; goto cleanup;
} }
...@@ -1549,18 +1543,11 @@ static int do_cmdtest_ioctl(struct comedi_device *dev, ...@@ -1549,18 +1543,11 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
/* load channel/gain list */ /* load channel/gain list */
if (cmd.chanlist) { if (cmd.chanlist) {
chanlist = chanlist = memdup_user(user_chanlist,
kmalloc(cmd.chanlist_len * sizeof(int), GFP_KERNEL); cmd.chanlist_len * sizeof(int));
if (!chanlist) { if (IS_ERR(chanlist)) {
DPRINTK("allocation failed\n"); ret = PTR_ERR(chanlist);
ret = -ENOMEM; DPRINTK("memdup_user exited with code %d", ret);
goto cleanup;
}
if (copy_from_user(chanlist, user_chanlist,
cmd.chanlist_len * sizeof(int))) {
DPRINTK("fault reading chanlist\n");
ret = -EFAULT;
goto cleanup; goto cleanup;
} }
......
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