linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vasyl Gomonovych <gomonovych@gmail.com>
To: sfr@canb.auug.org.au, greg@kroah.com, arnd@arndb.de,
	sudeep.dutt@intel.com, ashutosh.dixit@intel.com,
	gomonovych@gmail.com, dan.carpenter@oracle.com
Cc: linux-kernel@vger.kernel.org, linux-next@vger.kernel.org
Subject: [PATCH v2] misc: mic: Use memdup_user() as a cleanup
Date: Tue, 12 Dec 2017 11:40:58 +0100	[thread overview]
Message-ID: <1513075258-10860-1-git-send-email-gomonovych@gmail.com> (raw)
In-Reply-To: <20171212143910.146724d2@canb.auug.org.au>

Fix coccicheck warning which recommends to use memdup_user():

drivers/misc/mic/vop/vop_vringh.c:940:14-21: WARNING opportunity for memdup_user
drivers/misc/mic/vop/vop_vringh.c:998:8-15: WARNING opportunity for memdup_user

Generated by: scripts/coccinelle/memdup_user/memdup_user.cocci

Changelog:
 - v1:
   - Replace kzalloc + copy_from_user on memdup_user
 - v2:
   - Clear forgotten done label
     After merging the char-misc tree, today's linux-next build
     (x86_64_allmodconfig) produced this warning:
     drivers/misc/mic/vop/vop_vringh.c: In function 'vop_ioctl':
     drivers/misc/mic/vop/vop_vringh.c:1001:1: warning: label 'done' defined but not used [-Wunused-label]

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
---
 drivers/misc/mic/vop/vop_vringh.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c
index fed992e..27db64e 100644
--- a/drivers/misc/mic/vop/vop_vringh.c
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -937,13 +937,10 @@ static long vop_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 		    dd.num_vq > MIC_MAX_VRINGS)
 			return -EINVAL;
 
-		dd_config = kzalloc(mic_desc_size(&dd), GFP_KERNEL);
-		if (!dd_config)
-			return -ENOMEM;
-		if (copy_from_user(dd_config, argp, mic_desc_size(&dd))) {
-			ret = -EFAULT;
-			goto free_ret;
-		}
+		dd_config = memdup_user(argp, mic_desc_size(&dd));
+		if (IS_ERR(dd_config))
+			return PTR_ERR(dd_config);
+
 		/* Ensure desc has not changed between the two reads */
 		if (memcmp(&dd, dd_config, sizeof(dd))) {
 			ret = -EINVAL;
@@ -995,17 +992,12 @@ static long vop_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 		ret = vop_vdev_inited(vdev);
 		if (ret)
 			goto __unlock_ret;
-		buf = kzalloc(vdev->dd->config_len, GFP_KERNEL);
-		if (!buf) {
-			ret = -ENOMEM;
+		buf = memdup_user(argp, vdev->dd->config_len);
+		if (IS_ERR(buf)) {
+			ret = PTR_ERR(buf);
 			goto __unlock_ret;
 		}
-		if (copy_from_user(buf, argp, vdev->dd->config_len)) {
-			ret = -EFAULT;
-			goto done;
-		}
 		ret = vop_virtio_config_change(vdev, buf);
-done:
 		kfree(buf);
 __unlock_ret:
 		mutex_unlock(&vdev->vdev_mutex);
-- 
1.9.1

  reply	other threads:[~2017-12-12 10:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12  3:39 linux-next: build warning after merge of the char-misc tree Stephen Rothwell
2017-12-12 10:40 ` Vasyl Gomonovych [this message]
2017-12-12 11:49   ` [PATCH v2] misc: mic: Use memdup_user() as a cleanup Greg KH
2017-12-12 13:22     ` Gomonovych, Vasyl
2017-12-13  9:30       ` Greg KH
2017-12-12 11:49 ` linux-next: build warning after merge of the char-misc tree Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513075258-10860-1-git-send-email-gomonovych@gmail.com \
    --to=gomonovych@gmail.com \
    --cc=arnd@arndb.de \
    --cc=ashutosh.dixit@intel.com \
    --cc=dan.carpenter@oracle.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=sudeep.dutt@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).