public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] VMCI:  Use memdup_user() as a cleanup
@ 2017-11-22 15:29 Vasyl Gomonovych
  2017-11-22 15:55 ` Joe Perches
  2017-11-22 22:42 ` [PATCH v2] " Vasyl Gomonovych
  0 siblings, 2 replies; 4+ messages in thread
From: Vasyl Gomonovych @ 2017-11-22 15:29 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, gomonovych

Fix coccicheck warning which recommends to use memdup_user():
drivers/misc/vmw_vmci/vmci_host.c:757:11-18: WARNING opportunity for memdup_user
Generated by: scripts/coccinelle/memdup_user/memdup_user.cocci

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
---
 drivers/misc/vmw_vmci/vmci_host.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 8a16a26e9658..b8468b864bcd 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -754,18 +754,12 @@ 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)) {
+		vmci_ioctl_err("cannot allocate memory to set cpt state (type=%d)\n",
+				set_info.cpt_type);
+		return PTR_ERR(cpt_buf);
 	}
 
 	cid = vmci_ctx_get_id(vmci_host_dev->context);
@@ -774,7 +768,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;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-22 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-22 15:29 [PATCH] VMCI: Use memdup_user() as a cleanup Vasyl Gomonovych
2017-11-22 15:55 ` Joe Perches
2017-11-22 20:46   ` Gomonovych, Vasyl
2017-11-22 22:42 ` [PATCH v2] " Vasyl Gomonovych

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox