summaryrefslogtreecommitdiffstats
path: root/drivers/misc/vmw_vmci
diff options
context:
space:
mode:
authorWen Yang <wen.yang99@zte.com.cn>2018-12-10 19:36:07 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-19 10:26:31 +0100
commit8995fa1e1c9bcb76d407b860770e640b60ed8c76 (patch)
treeb72a5a69c9b9a0fbacd858b2cd795d0e89cb720d /drivers/misc/vmw_vmci
parentf88fd666051b08eb3f3118e2dd8508bf0247af4c (diff)
downloadlinux-8995fa1e1c9bcb76d407b860770e640b60ed8c76.tar.bz2
VMCI: Use memdup_user() rather than duplicating its implementation
Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. Signed-off-by: Wen Yang <wen.yang99@zte.com.cn> CC: Arnd Bergmann <arnd@arndb.de> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CC: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/vmw_vmci')
-rw-r--r--drivers/misc/vmw_vmci/vmci_host.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index edfffc9699ba..5da1f3e3f997 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -750,19 +750,10 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
if (copy_from_user(&set_info, uptr, sizeof(set_info)))
return -EFAULT;
- cpt_buf = kmalloc(set_info.buf_size, GFP_KERNEL);
- if (!cpt_buf) {
- vmci_ioctl_err(
- "cannot allocate memory to set cpt state (type=%d)\n",
- set_info.cpt_type);
- return -ENOMEM;
- }
-
- if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf,
- set_info.buf_size)) {
- retval = -EFAULT;
- goto out;
- }
+ cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf,
+ set_info.buf_size);
+ if (IS_ERR(cpt_buf))
+ return PTR_ERR(cpt_buf);
cid = vmci_ctx_get_id(vmci_host_dev->context);
set_info.result = vmci_ctx_set_chkpt_state(cid, set_info.cpt_type,
@@ -770,7 +761,6 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0;
-out:
kfree(cpt_buf);
return retval;
}